|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
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. |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exit status | MartyIX | Shell Programming and Scripting | 9 | 09-09-2008 05:47 AM |
| checking exit status of a shell script | kdipankar | Shell Programming and Scripting | 2 | 05-09-2006 01:08 AM |
| Checking Exit Status | PrimeRibAndADew | Shell Programming and Scripting | 4 | 10-19-2005 03:01 PM |
| exit status | moxxx68 | Shell Programming and Scripting | 1 | 12-04-2004 06:27 PM |
| ftp exit status. | oracle8 | UNIX for Advanced & Expert Users | 1 | 10-21-2001 11:34 PM |
|
|