Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 06-15-2007, 01:48 PM   #1
LQ Newbie
Registered: Jan 2005
Posts: 18

Rep: Reputation: 0
FTP files to remote server with a shell script

I've written the following script to make backups of various important directories on my server, and to FTP them to another, remote server.

The first part of the script works fine (I've included it for reference - others may find it useful), but the problem is with the FTP part. The first file is uploaded absolutely fine, but after that, nothing is transferred. The output on the command line is:
mput Nightly_Exalin_DNS_200706151937.tar.gz? mput Nightly_Exalin_MAIL_200706151937.tar.gz? mput Nightly_Exalin_MySQL_200706151937.tar.gz? mput Nightly_Exalin_Users_200706151937.tar.gz?
Nightly_Exalin_DNS_200706151937.tar.gz appears as it should, but none of the others!

The script:

#CD to the backup directory, and move all the existing backups to the archive folder
cd /dir/backup/files
mv Nightly_Exalin_* archive

#Enter the archive folder, and delete all files older than two days
cd archive
find Nightly_Exalin_*.tar.gz -mtime +2 -exec rm -f {} \;
cd ../

#Compress all the important directories
tar -zcvf Nightly_Exalin_Users_`date '+%Y%m%d%H%M'`.tar.gz /home/* --exclude backupuser
tar -zcvf Nightly_Exalin_MySQL_`date '+%Y%m%d%H%M'`.tar.gz /var/lib/mysql/*
tar -zcvf Nightly_Exalin_DNS_`date '+%Y%m%d%H%M'`.tar.gz /var/named/*
tar -zcvf Nightly_Exalin_MAIL_`date '+%Y%m%d%H%M'`.tar.gz /var/spool/*

#Things work fine up to here

#FTP the backups to a remote server
ftp -n <<EOFTP
quote user name
quote pass password
cd backup
mput Nightly_Exalin_*.tar.gz
I've also discovered that if I run the above commands manually, then the transfer is completed as expected - it is only when running it as part of the above script that the problems occur.

Thanks for any help.

Last edited by Pezzoni; 06-15-2007 at 02:03 PM.
Old 06-15-2007, 01:51 PM   #2
Registered: Dec 2006
Distribution: Slackware 11
Posts: 144

Rep: Reputation: 15
You may have better luck using 'expect'.
Old 06-27-2007, 07:01 AM   #3
LQ Newbie
Registered: Jan 2005
Posts: 18

Original Poster
Rep: Reputation: 0
Managed to fix this one:

ftp -n <<EOFTP
ftp -n -i <<EOFTP
And it seems to be fine!


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
Cannot run shell script on the remote server haresh_dba Linux - General 2 04-14-2007 09:26 AM
Is there a way to easily shutdown a remote linux server with a shell script? bdb4269 Programming 7 01-26-2007 04:08 PM
Remote Win Bat File execute Shell Script on AIX Server DriveMeCrazy AIX 5 05-26-2004 06:24 PM
Connection, login and upload files to ftp server via shell script Paulo Ges Linux - Networking 2 02-21-2004 01:01 PM
Running FTP inside Shell Script truncates files jbhanc0125 Red Hat 3 01-16-2004 11:37 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:18 AM.

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