LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 03-02-2004, 02:39 PM   #1
rkane
Member
 
Registered: May 2003
Location: Ohio
Distribution: Slackware
Posts: 47

Rep: Reputation: 15
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.
 
Old 03-02-2004, 02:50 PM   #2
rkane
Member
 
Registered: May 2003
Location: Ohio
Distribution: Slackware
Posts: 47

Original Poster
Rep: Reputation: 15
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.
 
Old 03-04-2004, 05:05 PM   #3
DrJibe
LQ Newbie
 
Registered: Mar 2004
Posts: 1

Rep: Reputation: 0
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 
tar: Removing leading `/' from member names
spawn ftp 217.20.xx.xx
Connected to 217.20.xx.xx (217.20.xx.xx).
220 ProFTPD 1.2.8 Server (Debian)
Name (217.20.xx.xx:root): bihh
331 Password required for bihh.
Password:
230 Anonymous access granted, restrictions apply.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd bac[root@mrbrown __B]#
So the script tried to issue "cd backup" but it didn't get that far ... and "timeout -1" should prevent that, shouldn't it?!

Any ideas would be appreciated!

thnx,
Bernd
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
backup server ; network file system / ftp-server ? markus1982 Linux - Security 5 06-06-2007 05:15 PM
Cron Backup TPupAZ Linux - Software 7 02-11-2005 07:49 AM
Can a backup be done with cron? sadly so Solaris / OpenSolaris 3 02-03-2005 01:28 AM
SCRIPT: backup defined files/dirs to FTP-server markus1982 Linux - Software 0 05-25-2003 06:06 AM
Need script to dump database, ftp file to backup server glock19 Linux - Networking 17 05-12-2003 05:56 PM


All times are GMT -5. The time now is 09:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration