Email on shutdown/restart

Discussion in 'Programming/Scripts' started by Mosquito, Jun 18, 2009.

  1. Mosquito

    Mosquito New Member

    I am looking for a (hopefully) simple script that sends out an email on system restart and system halt. Unfortunately, Google hasn't been helpful in this search (or my Google-fu is off today).

    Does anyone have a script - either cron, init.d or something else entirely - that will send out an email when a system shuts down and again when it comes back up? Same for restart. I'm also open to being pointed to a good resource. Like I mentioned before though, Googling for "send email on restart linux" hasn't turned up anything useful thus far.

    I realize it would send two emails each time - however, this does two things for me 1.) Says the restart was successful 2.) Identifies when there was a power failure (ie. I only got the start up email, but no shutdown).

    It may matter - I am using Red Hat based systems - CentOS 5.x and Fedora versions 5-11 (I know, its a big range and some need to be updated).

    Thank you
  2. id10t

    id10t Member

    Look at the mail command, or the program mailm. Then you'll want to write your simple script and put a link to it in rc0.d, rc3.d (and/or rc5.d) and rc6.d - one for shut down, one for restart.
  3. dipeshmehta

    dipeshmehta Member

  4. Mosquito

    Mosquito New Member

    id10t, your response was able to give me a better idea what to Google for, thank you. I found this early this morning:

    Email on shutdown and restart (Linux)

    Thanks for the help and idea.

Share This Page