Linux.com

Home Linux Community Forums Software Command Line How do I send email on shutdown or reboot

How do I send email on shutdown or reboot

Link to this post 19 Jun 09

Hi,

I am attempting to send an email on system shutdown and start up. Right now I have a cron entry that utilizes the @reboot option. This fulfills one of my needs - getting the email on start up. How would I go about getting the system to send out an email at the other end of the process? Namely, I want an email as the system is shutting down. Theoretically, this means I should receive two emails every time the system starts (once because I shut it down or rebooted it, and once because it came back up).

Thank you

Link to this post 19 Jun 09

McFly wrote:

Hi,

I am attempting to send an email on system shutdown and start up. Right now I have a cron entry that utilizes the @reboot option. This fulfills one of my needs - getting the email on start up. How would I go about getting the system to send out an email at the other end of the process? Namely, I want an email as the system is shutting down. Theoretically, this means I should receive two emails every time the system starts (once because I shut it down or rebooted it, and once because it came back up).

Thank you

See if this thread helps you. It is RH/Centos oriented. In the initscript you make, you could have a "start" stanza which gets called upon startup, and a "stop" stanza which gets called upon shutdown/reboot. Shout back if this is not clear to you.

Link to this post 20 Jun 09

Thank you. That looks very useful. I believe I can modify that to send out the email I'm looking for.

Thanks.

Link to this post 23 Jun 09

McFly wrote:

Thank you. That looks very useful. I believe I can modify that to send out the email I'm looking for.

Thanks.

Cheers!

Link to this post 24 Jun 09

As a follow up - in addition to the link posted above with very detailed directions, I also found the tutorial below. The link above showed up to set up the shutdown side of this project and a little extra searching showed how to do the start up (actually, I learned about the @reboot cron ability too)

To see others, run

man 5 cron
. Spiffy little entries there. Would have been very nice to have a @shutdown option. Alas...

Send email on shutdown and restart (Linux)

Anyway, thanks again for pointing me to the thread above atreyu. It was very useful in showing me what I needed and crafting the correct Google search to get the rest of what I needed.

Link to this post 01 Jul 09

You can simply put a small script that takes the time, and send you an Email with either 'boot' or 'shutdown'.

Put it in the relevant rc's, and that's it.

For example, a simple 'boot' script can be:

#!/bin/bash
mail -s "boot at `date`" you@yourdomain.com

Plain, simple. Leave the hassle for other folks.

Good luck!
Dotan

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board