Recently I have setup a cronjob to automatically restore a mysql database. So I created a script like the following
mysql -u<username> -p<password> -h<hostname> <dbname> < <path_of_exported_database.sql
This script was scheduled through cron service to run every some hours, but I didn’t know if it run with success or no.
I placed this row in the crontab declaration
MAILTO="myemailaddress"
in order to be notified in case of cron job execution failure. But it was important also to know if the job run or not and with what result.
So I placed the following code under the script for the database restore
if [[ $? -eq 0 ]] ;then echo "MySQL Restore was successful." else echo "Problems with MySQL Restore." fi
and now a notification is being sent in every execution of this cron job