I have been asked to handle errors arising from
ftp.
This code does not handle errors.
if test $# -ne 3
then
echo "Usage: $0 <PROCESSING_DIR> <CURRENT_DIR> <FTP_DIR>"
exit 1;
fi
process_dir=$1
current_dir=$2
ftp_dir=$3
cd $process_dir
ls CSH*.HIST > $current_dir/temp_file.txt
ls BSH*.HIST >> $current_dir/temp_file.txt
ls DSH*.hist >> $current_dir/temp_file.txt
cat $current_dir/temp_file.txt
| \
while read line
do
wc -c $process_dir/$line > $current_dir/temp.txt
file_size=`awk '{print $1}' $current_dir/temp.txt`
if [[ $file_size > 0 ]]; then ##error needs to be handled from here.
echo "
user USERNAME PASSWORD
lcd $process_dir
bin
prompt
cd $ftp_dir
mput $line
bye
" | ftp -ivn mopppgstrtadm6.pfizer.com
echo "PDMA files successfully transferred to startrak."
else
echo "$line is a 0 byte PDMA file."
fi
done ##error needs to be handled till here.
rm -f $current_dir/temp.txt
rm -f $current_dir/temp_file.txt
I wish to replace the ftp code with this code:
if [[ $file_size > 0 ]]; then ##error needs to be handled from here.
echo "
user ibmpdma st4rtr4k!pdm4
lcd $process_dir
bin
prompt
cd $ftp_dir
mput $line
bye
" | ftp -ivn mopppgstrtadm6.pfizer.com >> $LOG_FILE
# testing the exit status of FTP
egrep "Transfer complete" $LOG_FILE >/dev/null
if [ $? = 0 ]
then
echo >> $LOG_FILE
echo "FTP Successfully Done" >> $LOG_FILE
else
echo >> $LOG_FILE
echo "FTP UnSuccessfull" >> $LOG_FILE
exit 1
fi
else
echo "$line is a 0 byte PDMA file."
fi
but this code does not identify reason for failure:
I want to have something like FTP UnSuccessful due to:
1.non availability of space on the ftp server. or
2.incorrect username/password while logging into the ftp server. or
3.lcd and cd path not available.
How is this possible:
USERNAME AND PASSWORD REPLACED
Vee_Mod
Start Free Trial