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>&1
This 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 to detect.
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/null if [ $? -eq 0 ] then echo "PASS" else echo "FAIL" >&2 fi
I 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?