cron nightly backup to ftp server
I am having a problem with my shell and expect scripts. I have a backup run from cron every evening at 630 pm, and it runs through the script and creates the tar archives and also gzip's them, but it never ftp's them to the server.
I can manually run the script from the shell and everything works as it is supposed to. What would be causing my problem. Here are the scripts I am using. The first does the backup and calls the second which ftp's to the server. #!/bin/sh # # #setup username for ftp userString="ooer" pswdString="can't let you have that" #read old date and replace with new date OLD_DATE=`cat /home/__B/old` DATE=`date +%m-%d-%y` echo $DATE > /home/__B/old #delete last backup file rm /home/__B/usrlocal-${OLD_DATE}.tar.gz rm /home/__B/home-${OLD_DATE}.tar.gz #backup /usr/local to /home/rcable/__B/ tar -czf /home/__B/usrlocal-${DATE}.tar.gz /usr/local tar -czf /home/__B/home-${DATE}.tar.gz /home/rcable /home/mrtg #connect script to server ./ftpscript ${DATE} exit 0 Expect Script #! /usr/bin/expect -f # # set timeout -1 # Make FTP Connection to Server spawn ftp 192.168.160.132 expect "Name" send "ooer\r" expect "Password:" send "can't let you have that\r" expect "ftp>" send "cd backup\r" expect "ftp>" # [lindex $argv 0] gets the first argument passed to this script send "send usrlocal-[lindex $argv 0].tar.gz\r" expect "ftp>" send "send home-[lindex $argv 0].tar.gz\r" expect "ftp>" send "bye" I am thoroughly confused about this because it works great when ran from the shell, but when I use it as a cron it doesn' t seem to work. Well now that I've typed this all, I think I figure it out. I think I can fix it by changing the line ./ftpscript ${DATE} to /home/__B/ftpscript ${DATE} If not I will let you know tomorrow. If you have any thoughts please feel free to share them. |
Stupid Stupid Stupid
Well, nothing like putting it down and then realizing what you are doing wrong. Well at least I can say linuxquestions.org helped me. They made me write down my problem and I came to a solution after seeing it in a different way.
So the problem was I was trying to access a script from a directory without being sure I was in that directory, and the first correction I posted above didn't fix the problem. Ultimately I had to do: cd /home/__B ./ftpscript ${DATE} And this made sure that the ftp script knew where to get the files it was uploading. Thanks so much LinuxQuestions. |
thanks for putting down your script here - it was a very helpful starting point for me. But I do have a problem: it seems as if the first script is not waiting for the 2nd script to finish but kills it before it's ready. I start up the script for testing purposes manually and tars the files but can't get to the point where they are actually uploaded - while the 2nd script is trying to change the directory I back at the prompt. Any idea what this can be about? Here's the output from my terminal
Code:
[root@mrbrown __B]# ./fmserver_backup_to_ftp.sh Any ideas would be appreciated! thnx, Bernd |
All times are GMT -5. The time now is 09:33 AM. |