-   Linux - General (
-   -   Getting cron result mailed back (

Swakoo 08-05-2008 02:32 AM

Getting cron result mailed back
hi guys,

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 but nothing happen, but the server rebooted though..

is the mailto meant for this purpose? or so I read, it seems like it is...

eggixyz 08-05-2008 02:44 AM

Hey There,

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

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 :)

Best wishes,


chrism01 08-05-2008 03:02 AM

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.

Mr. C. 08-05-2008 04:21 AM

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 10:17 AM.