Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an Ubuntu 10.04 desktop at home that runs 24/7. Recently, I've noticed that the machine occasionally restarts on its own (approx once per month). I would like to set this server up so that I get an email every time the server starts. I would like to get the email at my gmail account and I'll set up another gmail account for the server to use to send emails (if necessary).

As an added bonus, it would be great if the email could contain some sort of diagnostic information pertaining to what caused the server to crash and restart.


share|improve this question
For actually sending the email with sendmail, check out… – cpast Jan 1 '13 at 20:04

It's hard to track why your computer crashed and restarted, but you can e-mail your logs with the notification e-mail. For advanced monitoring, I suggest trying out Zabbix, NagiOS or Cacti. However, here's a simple Python 2.7 script for sending an e-mail with a command "./ username_for_gmail path_to_letter":

import smtplib
import getopt
import sys

args = getopt.getopt(sys.argv[1:], ":")
laiskas = args[1][1]
SENDER = "no-reply@" + args[1][0]
mssg = open(laiskas, 'r').read()

server = smtplib.SMTP('',587)
server.login(args[1][0] + "","R7olM6Qw")

You have to change R7olM6Qw to your own GMail password. Also, please change RECIPIENTS variable for your addresses. The script needs smtplib and python2.7, which may have to be installed on your server from apt.

Then you can create a simple text file next to the script:

Subject: Computer powered on!
Random text here...

In the end, just add a new line to the /etc/rc.local file:

/path/to/the/python/script gmail_username /path/to/the/letter

However, this is not a safe method as you will be storing your password insecurely, so I suggest creating a mailbox just for that. Also, please, mind it and chmod all scripts in order to prevent other users doing anything with them.

Instead, I think that it is rather more reasonable to have a separate server with PHP mailer script available only for servers' IPs. In that case, the separate server would be doing the mailing service securely, while leaving your other servers only with curl or wget for pushing the notifications.

share|improve this answer

I see at least two possible options:

  1. Add a new cronjob (e.g. @reboot root mail -s "I just rebooted" your@mail.tld
  2. Install logcheck; it will send you the log messages containing the reason for the reboot (if there are any log entries about them)
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .