Hi,
I am totally new to shell scripts. I have a requirement to send mails if a job fails. I wrote the below script and setup the cron job. However, the scripts sends mail even if the job is successful. Could anyone please help me to resolve this issue:
My script:
#!/bin/bash
cd /interface/i_tane01/
mv /PROD/incoming/ABC.txt /PROD/archive/ABC`date '+_%m%d%y_%H:%M:%S'`.txt
if [ "$?" -ne "0" ];
then echo "Archeiving Error" | mailx -s "ABC_Err"
ABC@123.com
exit 1
fi
When I execute the same script manually using ./file.sh command, it works very well. But, when I set this in cron job, it is sending mails everytime.
Your help on this is very much appriciated.
Thanks,