Please check the below ftp related job, which is deleting the files from remote host. Problem is it is not capturing the ftp failure error, and the exit status is still '0' eventhough the deletable files are not present in remote location OR ftp credential are incorrect.
ftp -n $REMOTEHOST1 <<EOD
user "$REMOTEUSER1" "$FTP_PASSWD"
del $OUTPUT_DIR/aaa.log
del $OUTPUT_DIR/bbb.log
del $OUTPUT_DIR/ccc.log
del $OUTPUT_DIR/ddd.log
bye
EOD
# Checking the success of the FTP call
EXIT_STATUS=$?
if [ EXIT_STATUS -ne 0 ];then
echo FTP Failed
exit 1
fi
Please see the result below:
/export/home/ITC_rlok>ftp*
+ export REMOTEHOST1=10.19.5.221
+ export REMOTEUSER1=ganap_01
+ export FTP_PASSWD=mysore001
+ export OUTPUT_DIR=/export/home/ganap/
+ ftp -n 10.19.5.221
+ 0<<
user "ganap_01" "mysore001"
del /export/home/ganap/aaa.log
del /export/home/ganap/bbb.log
del /export/home/ganap/ccc.log
del /export/home/ganap/ddd.log
bye
/export/home/ganap/aaa.log: No such file or directory.
/export/home/ganap/bbb.log: No such file or directory.
/export/home/ganap/ccc.log: No such file or directory.
/export/home/ganap/ddd.log: No such file or directory.
+ EXIT_STATUS=0
+ [ EXIT_STATUS -ne 0 ]
I dont know, how to handle this. Please suggest/guide me.
thats the return status of the ftp session established,
since it had completed successfully, the return status is 0
ftp session return status overrides the return status of the commands executed within the ftp session.
To acheive that, possible way could be redirect the ftp logs ( commands issued, output received from the ftp server )
once the ftp session is done,
parse the log,
to identify the operation was successfull or not
ftp return codes are available and with that it should be easier to identify the status of the operation
Then, what is the use of checking the exit status of the ftp command?
Can I skip the below testing block? When this can be used? Are there any other way to exit this condition with the exit status '1'?
EXIT_STATUS=$?
if [ EXIT_STATUS -ne 0 ];then
echo FTP Failed
exit 1
fi