LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-09-2008, 07:50 AM   #1
TalkingMarble
Member
 
Registered: May 2008
Location: Deventer, The Netherlands
Distribution: CentOS 5.0
Posts: 50

Rep: Reputation: 17
Arrow Bash script: return code ftp


Hello,

I'm using the code written below inside a bash script to transfer some files. In order to test the return code from the ftp, i supplied an invalid password. I was surprised by the fact that the ftp was successful. Can anybody tell me why it was successful and how i need to adjust the code?

ftp -inv <<EOF
open IP-address
user USER PASSWORD
lcd /Dir
cd /Dir
binary
put $1
quit
EOF
if [ $? -eq 0 ]
then
Echo “Successful”
Else
Echo “Failed”
fi

TIA

TalkingMarble
 
Old 05-09-2008, 09:04 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
the best way to troubleshoot these situations is to enter the commands manually and look at "$?" at each step.

In your scenario, you are testing the result after issuing a series of ftp commands--not a BASH command. I don't know what happens is that case.
 
Old 05-09-2008, 09:27 AM   #3
Asy
LQ Newbie
 
Registered: May 2008
Location: The Netherlands
Distribution: Ubuntu
Posts: 25

Rep: Reputation: 16
The problem here is that the return code comes from the ftp command. The ftp command itself runs fine, so the return-code is true.

To test a proper ftp your sender shoud put a second file and the you have to test if this file is received. By sending do it the other way round send an extra file if your transport is finished and transport the same file in a new ftp session back. The you are sure the ftp result is ok.
 
Old 05-09-2008, 09:37 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Given the explanation in the previous posts, you can redirect the standard error coming from the ftp command to a file, then check if the file has a size greater than zero and act accordingly, as in
Code:
ftp -inv << EOF 2> ftp.error
  open IP-address
  user USER PASSWORD
  lcd /Dir
  cd /Dir
  binary
  put $1
  quit
EOF
test -s ftp.error && echo Failed || rm ftp.error
Furthermore you can parse the content of the file (if any) and take different actions upon different error messages.
 
  


Reply



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
Possible to have perl code into bash script ? frenchn00b Programming 3 07-03-2007 12:56 PM
Bash command/script to return group of file IHateFriction Programming 3 03-09-2007 12:31 PM
Return code of a shell script zachos.v Linux - Software 3 10-10-2006 09:51 AM
bash script Want to capture return key and assign a value procfs Programming 9 07-07-2006 01:38 AM
return value from shell script to c code? khucinx Programming 1 05-13-2004 03:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:27 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration