I am attempting to write a bash script that backs up a mysql database and sends an e-mail stating whether if failed or was successful. I am using the following:
Code:
if [ $check != 0 ]; then
mail -s "Mysql Backup Successful" User1@domain.com <<< " I do not believe it, Please verify."
else
mail -s "Mysql Backup FAILED" User1@domain.com <<< " The blasted thing FAILED, Check your stuff."
fi
When I run it, I get "unexpected redirect" error.
I created separate scripts for each case and just copied and pasted the "mail -s ...." lines into them respectively. Then I called the newly create scripts as follows:
Code:
if [ $check != 0 ]; then
/home/fmadmin/mail_success.sh
else
/home/fmadmin/mail_fail.sh
fi
Now it works fine. Can someone advise me what is wrong with the first approach?
Thanks,
Keith