LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-22-2010, 12:43 AM   #1
edomingox
Member
 
Registered: Mar 2009
Posts: 49

Rep: Reputation: 15
Bash script problem with ftp session exiting the script early


I got this script that backs up a server and then keeps only the last 10 backups and removes the rest. Problem is, the part where it deletes any backups older than the last 10, it never reaches that. I'm guessing it is because the ftp session somehow exits the script entirely, especially if there is a problem with the ftp session. But just to make sure, I'm wondering if you all can look at the code to see if I am making it exit accidentally.

Here's the code. I left out data like ip address and directory/file names for my security purposes.

Code:
#ftp in and grab the file
ftp -in xx.xx.xx.xx << EOF
user user password
bin
cd /export/home/backup
lcd /data1
lcd $backupDir
lcd $backupDirNext
get file.cfg
get file.dmp
close
bye
EOF

#remove old backups here
 
Old 02-22-2010, 02:20 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,489

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Apparently the ftp code is correct. The close statement is not necessary, since you don't need to keep the ftp session open for further operations, but that cannot be an issue. You can try to save the stdout and stderr of the ftp command, using the verbose option for checking, e.g.
Code:
ftp -in -v xx.xx.xx.xx << EOF > ftpout.log 2> ftperr.log
or eventually try a different tool like curl for example.
By the way, are the files you want to retrieve actually downloaded to the local machine?
 
Old 02-22-2010, 06:21 AM   #3
edomingox
Member
 
Registered: Mar 2009
Posts: 49

Original Poster
Rep: Reputation: 15
ya. the files are there. and when i check if it was transferred, it is. I'm not sure what could be causing this. It could be the get command. I can try using curl and see what happens.
 
Old 02-22-2010, 07:06 AM   #4
edomingox
Member
 
Registered: Mar 2009
Posts: 49

Original Poster
Rep: Reputation: 15
I added the ftpout.log and ftperror.log and the error log shows nothing and the out log shows nothing other than navigating through the directories. The files were transferred fine, but the anything after that does not execute. I had an echo line after EOF and it never executed. So I'm still stumped on why it exits.
 
Old 02-22-2010, 08:21 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,489

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Quote:
Originally Posted by edomingox View Post
I added the ftpout.log and ftperror.log and the error log shows nothing and the out log shows nothing other than navigating through the directories. The files were transferred fine, but the anything after that does not execute. I had an echo line after EOF and it never executed. So I'm still stumped on why it exits.
Ok. First check if you see the following line at the end of ftpout.log:
Code:
221 Goodbye.
this means that the remote server answered to your greetings and all the ftp commands have been executed properly. If this is the case, I suspect you've placed the closing EOF keyword of the here document at the wrong place: take in mind that it must be at the beginning of the line (no leading spaces are allowed, nor trailing hidden/control characters). If the syntax is not correct the end of the here document cannot be never reached and every subsequent line of code is passed as standard input to the ftp command (which has already closed the connection) and ignored.
 
Old 02-23-2010, 05:39 AM   #6
edomingox
Member
 
Registered: Mar 2009
Posts: 49

Original Poster
Rep: Reputation: 15
That worked. I actually had a space after EOF. I also had a #comment after it too. I didn't think that would of affected it when I retyped it on this post so I didn't include it.

Thanks for your help.
 
  


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
Very n00b question about exiting a bash script wimnat Linux - Software 11 05-28-2009 08:11 PM
ssh session within a bash script Tamaros Programming 1 05-11-2008 03:38 AM
Run intractive ssh session in a bash script MasterC Programming 2 10-15-2007 05:08 PM
Automate FTP session using Shell Script kalyanofb Programming 2 04-07-2007 08:44 AM
how to have bash script check whether it's a x session? bkeeper Linux - Newbie 9 02-21-2006 06:31 AM


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

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