Notification on server restart

Many times you find out that your server has been rebooted, but that information comes to late for you. For those cases, and not only, you can set a cron job that would sent a notification to your email address, each time when your server is rebooted. For this run first

crontab -e

(this opens up vi as your crontab editor) and at the end of the file add this command:

@reboot echo “`date +%r` `date +%b-%d-%Y` the server has been restarted.” | mail -s “`hostname` restart” dragos@fedorovici.com

This way each time when your server is restarted a notification is sent to your email address. The notification includes the hostname of the machine (in title) and the date when the server has been restarted (on body).