sergio_educacionit

file_archiver.sh

Apr 16th, 2026 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.64 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. fecha=$(date +%s)
  4.  
  5.  
  6. # tiene que ser un archivo
  7. archivo_origen=$1
  8.  
  9.  
  10. # [ -f ... ] es lo mismo que test -f ...
  11.  
  12. if [ -f "$archivo_origen" ]; then
  13.    
  14.     # se guarda nombre de archivo sin ruta
  15.     nombre_archivo=$(basename $archivo_origen)
  16.  
  17. else
  18.     echo "El archivo no exite."
  19.     exit 1
  20. fi 
  21.  
  22.  
  23.  
  24. # tiene que ser un directorio
  25. # '%/' elimina la barra al final de la cadena
  26.  
  27.  
  28. ruta_destino=${2%/}
  29.  
  30.  
  31. test -d $ruta_destino && \
  32.    
  33.     { cp $archivo_origen ${ruta_destino}/${nombre_archivo}.${fecha}; \
  34.  
  35.     gzip ${ruta_destino}/${nombre_archivo}.${fecha}; \
  36.  
  37.     ls -1 ${ruta_destino}/*.gz; } || { echo no existe el directorio; exit 1; }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment