copy whole directory to ftp server
Hello
I have this scripts that is meant to create certain files and a directory by date and once its finished its meant to copy that direcory an the example ftp server. Can someone check the script for me and advise? #!/bin/bash # script that FTPs the given file to a host FTPHOST="example.example.com" DATE=`date +%d%m%Y` DATESTRING=`date +%d/%m/%Y\ %H:%M:%S` LOG="/data/logs/ftpScript.log" FTPINPUT="/data/printData/ftpCommandFile" FTPOUTPUT="/data/printData/ftpOutputFile" DATADIR="/data/printData" TIMESTRING=`date +%H%M%S` # do we have an argument? if [ -z "$1" ]; then echo $DATESTRING" - ERROR: no argument supplied" >> $LOG exit fi # is it a file? if [ ! -e "$1" ]; then echo $DATESTRING" - ERROR: supplied argument does not exist" >> $LOG exit fi # does the date folder exist in the data dir? if [ ! -d $DATADIR/$DATE ]; then mkdir $DATADIR/$DATE # add a line to make the directory on the FTP host EXTRALINE="mkdir $DATE" else EXTRALINE="" fi # what is just the filename portion? FILENAME=`basename "$1"` # does the target file already exist in the target folder? if [ -e "$DATADIR/$DATE/$FILENAME" ]; then NEWFILENAME="$FILENAME.$TIMESTRING" else NEWFILENAME="$FILENAME" fi # copy the argument there cp "$1" "$DATADIR/$DATE/$NEWFILENAME" # check that it copied fine if [ ! -e "$DATADIR/$DATE/$NEWFILENAME" ]; then echo $DATESTRING" - ERROR: error copying file" >> $LOG exit fi DIFFSTRING=`diff "$1" "$DATADIR/$DATE/$NEWFILENAME" 2>&1` if [ ! -z "$DIFFSTRING" ]; then echo $DATESTRING" - ERROR: copied files differ" >> $LOG exit fi # make the FTP command script echo "user oper oper" > $FTPINPUT echo "cd moblas6" >> $FTPINPUT echo $EXTRALINE >> $FTPINPUT echo "cd $DATE" >> $FTPINPUT echo "bin" >> $FTPINPUT echo "lcd $DATADIR/$DATE" >> $FTPINPUT echo "put \"$NEWFILENAME\"" >> $FTPINPUT echo "bye" >> $FTPINPUT # execute the script ftp -nvi $FTPHOST < $FTPINPUT > $FTPOUTPUT 2> /dev/null # log the transmission echo $DATESTRING" - '$1' sent" >> $LOG # and exit exit |
It might be quicker if you just add 'set -x' and post the output
Code:
#!/bin/bash |
All times are GMT -5. The time now is 09:08 PM. |