I have a simple “main” shell script that does a few prep things and then calls another shell script that uploads a file to an ftp site. I’d like to know how I can wait and check the exit code of the called shell script and also how I could easily check whether the FTP file was actually successfully uploaded and provide a proper exit code (0 or 1)
thank you
main script:
#!/bin/sh
# check for build tools first
FTP_UPLOAD_SCRIPT=~/Desktop/ftp_upload.sh
if [ -f "$FTP_UPLOAD_SCRIPT" ]; then
echo "OK 3/5 ftp_upload.sh found. Execution may continue"
else
echo "ERROR ftp_upload.sh not found at $FTP_UPLOAD_SCRIPT. Execution cannot continue."
exit 1
fi
# upload the packaged installer to an ftp site
sh $FTP_UPLOAD_SCRIPT
# check the ftp upload for its exit status
ftp_exit_code=$?
if [[ $ftp_exit_code != 0 ]] ; then
echo "FTP ERRORED"
exit $ftp_exit_code
else
echo $ftp_exit_code
echo "FTP WENT FINE"
fi
echo "\n"
exit 0
ftp_upload_script:
#!/bin/sh
FTP_HOST='myhost'
FTP_USER='myun'
FTP_PASS='mypass'
FTPLOGFILE=logs/ftplog.log
LOCAL_FILE='local_file'
REMOTE_FILE='remote_file'
ftp -n -v $FTP_HOST <<SCRIPT >> ${FTPLOGFILE} 2>&1
quote USER $FTP_USER
quote PASS $FTP_PASS
binary
prompt off
put $LOCAL_FILE $REMOTE_FILE
bye
SCRIPT
echo $!
I have come up with a solution that both double checks the ftp upload and then provides an appropriate exit code.