Este es mi codigo:
Código:
#!/bin/bash
##This script makes a backup of an especified directory
##Programmed by Raúl Sánchez
##I check the parameters
if [ $# -ne 1 ]
then
echo You must enter a valid directory
echo usage: $0 directory
exit 1
fi
dir=$1 ##dir is the directory specified by the first parameter
## make sure $dir is a directory (not a file) and has write privilege
if [ ! -d $dir ] || [ ! -w $dir ]
then
echo $dir not a writable directory
exit 1
fi
##I enter into the directory
cd $dir
files=*
## variable files expands to include a list of all files
## in the directory
## examine all files in the directory
## to the user
for file in $files
do ## take a look at every file
if [ ! -f $file ]
then ## if not an ordinary file then skip
continue ## treat only ordinary files
fi
echo " " ## gives a blank line
ls -l $file ## list file and its attributes
while [ 1 ] ## infinite loop
do
echo "***** Do you want to create a backup of $file??"
echo -n "[y(yes), n(no)]" ## " is necessary to avoid misinterpreting *
read c
case $c in ## what did user select
y) ## yes -- I create the backup
if [ ! -r $file ]
then ## can I read this file?
echo cannot read $file
else
cp $file $file.bak ##copy the file
echo "***** $file saved"
fi
break;; ## to handle next file
n) ## no, don't save file
echo "***** $file not saved"
break;; ## to handle next file
esac
done ## while loop
done ## for loop
exit 0
Gracias y Saludos