Welcome to the Linux Foundation Forum!

How do I send email on shutdown or reboot

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

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

  • Posts: 216
    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.
  • Posts: 3
    Thank you. That looks very useful. I believe I can modify that to send out the email I'm looking for.

    Thanks.
  • Posts: 216
    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!
  • Posts: 3
    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
    1. 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.
  • Posts: 1
    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:
    1. #!/bin/bash
    2. mail -s "boot at `date`" you@yourdomain.com
    Plain, simple. Leave the hassle for other folks.

    Good luck!
    Dotan

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training