Getting cron result mailed back
i am testing to cron my servers to reboot monthly by calling /sbin/reboot
but is it possible to get cron to mail me when it actually does that?
i tried firstname.lastname@example.org but nothing happen, but the server rebooted though..
is the mailto meant for this purpose? or so I read, it seems like it is...
Quick and dirty if you want to get email no matter what distro you're on. If you're cron entry is, let's say:
59 23 * * * /usr/sbin/reboot
just change it to this:
59 23 * * * /usr/sbin/reboot 2>&1|/usr/lib/sendmail email@example.com
Now as for the reboot notification, in and of itself, you may still have issues since the machine is shutting down. If you could use a program like shutdown with the -g flag to set a grace period, like 60 seconds, the reboot would have time to send out a mail before it potentially cripples the mailing subsystem by sending it a TERM signal at reboot :)
I'd put both in a small shell script, calling the sendmail first, so it won't reboot until it's already sent the email.
You can also add a send email call to /etc/rc.local, which is the last thing called at boot time. This will confirm the system is back up.
You may need a little delay in between your sendmail and reboot, if you want to ensure that the mail has left the mail queue and arrived at its destination.
|All times are GMT -5. The time now is 01:30 PM.|