LinuxQuestions.org
Visit Jeremy's Blog.
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, 08: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, 10:04 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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, 10: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, 10:37 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
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


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


All times are GMT -5. The time now is 10:21 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration