Monday, October 08, 2012

How to trap FTP Success / Failure


#-- Function doftp
doftp()
{
ftp -in $host << EOF_MYFTP
user $user $password 
put YOURFTP.FILE $dest_dir/$dest_file
dir $dest_dir/$dest_file
bye
EOF_MYFTP
}

#-- Run ftp
doftp 1>doftp.log 2>&1

#-- Check logfile for "No such file or directory"
NUM_ERRRORS=`grep -c "No such file or directory" doftp.log`

if [[ ${NUM_ERRORS} -eq 0 ]]; then
  echo "File(s) transferred successfully"
else
  echo "Errors transferring file(s):"
  grep "No such file or directory" doftp.log |awk '{print $1}'
fi

exit ${NUM_ERRORS}

No comments:

Post a Comment