The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to get the exit status yhacks Shell Programming and Scripting 1 05-19-2008 05:06 AM
checking exit status of a shell script kdipankar Shell Programming and Scripting 2 05-08-2006 10:08 PM
Checking Exit Status PrimeRibAndADew Shell Programming and Scripting 4 10-19-2005 12:01 PM
tar exit status thorndike UNIX for Dummies Questions & Answers 3 01-22-2002 12:39 PM
ftp exit status. oracle8 UNIX for Advanced & Expert Users 1 10-21-2001 08:34 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-17-2002
Registered User
 

Join Date: May 2002
Posts: 6
Checking the exit status of ftp

#!/bin/sh
# upload_file.sh

FILENAME=$1

ftp -v -n -i <<-EOF1
open remote_server
user username password
cd remote_directory
lcd local_directory
type binary
mput ${FILENAME}
EOF1
rc=$?
echo "Return code is ${rc}"


I am calling this script from another script.
My problem is that the exit status of the above script is always 0, i.e. successful, even if remote_directory, local_directory or FILENAME don't exist.

I want to check the exit status of this script in the calling script and take appropriate action based on whether the ftp was successful or not. I am not sure if I am doing something wrong.
Forum Sponsor
  #2 (permalink)  
Old 06-04-2002
Registered User
 

Join Date: Jun 2002
Location: North Texas
Posts: 3
This is not so much as checking the exit code but a way to validate the transfer:

FILENAME=$1

ftp -v -n -i <<EOF > /tmp/ftplog.$$
<<<ftp stuff>
EOF

Then either in the upload script or in the calling script store the size of the file just tranferred into an environment variable using ls -l and awk. Then cat /tmp/ftplog.$$. You want to grep for the line that reads "XXX bytes transferred" (or however it reads. It's been a long time since I've done this) and awk out the "XXXX" bytes into a second environment variable.

In the upload script it is simple to do a comparision and "exit 1" for an imcomplete or failed transfer. You could also cat/grep the tmplog for other error conditions such as failure to cd to the appropriate directories, etc. and exit with different return codes depending on the nature of the failure.

Either way this should be enough information point in you in the best direction you need to validate your transfers.

NOTE: this method works for binary transfers only. Ascii transfers show a lower number of bytes transfered.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:33 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0