I have created a bash script that runs automated EBS backups on AWS. It is kicked off via a cronjob:0 2 * * * /bin/bash /root/backup_snapshots.sh > backup.log 2>&1This works perfectly, but next thing I want to do is to add an exit code for whether or not the script runs successfully ( So I can configure a Nagios check on it). There is a few things I am going to be doing:Create the backup.log in /var/log/backup/ directory.Configure logrotate to rotate it daily, to make this check easier todetect.But one question I have is, is it possible to have cron write an exit code to the backup.log file I created? Or should I go with this type of implementation:Create crontab entry with a script that can kick off the actual script AND have an exit code like this:#!/bin/bash/root/backup_snapshots.sh 2> /dev/nullif [ $? -eq 0 ]then  echo PASSelse  echo FAIL >&2fiI want to make this as simple as possible so if cron can do it, awesome! If not, would the next best thing would be to create a bash script that executes backup_snapshots.sh and run via cron?
Adding an exit code to log file
cron;stdout;aws
#!/bin/bashexec 1>/var/log/backup/backup_sbapshots.log 2>&1if /root/backup_snapshots.shthen  echo PASSelse  echo FAILfiMake your cron script as shown which will put the cronjob run status in the backup log file. Note that there's no mention anywhere of the $? variable as  the if statement does it own it's own.