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'm looking for a simple way of getting an email alert whenever the diskspace of a server gets above X % or has less than X Mb free.

I don't need anything too special, I don't need graphs or anything like that, just an email to let me know when my server is about to run out of space so I can run cleanup jobs. Right now I'm looking into setting up cleanup jobs with Jenkins, I just need something in the mean time to make sure the server keeps running.

This is for an Ubuntu server.

share|improve this question
It's pretty easy to write your own simple shell script involving df, and mailx commands with crontab to schedule them. – mdpc Feb 12 '13 at 21:49
up vote 7 down vote accepted

I suggest you take a serious look at monit. It is a light weight local monitoring tool.

Your config for monitoring for the root filesystem would look as simple as this.

check filesystem rootfs with path /
    if space usage > 80% then alert

The global monit config would look about like this.

set daemon  180           # check services at 3-minute intervals
#     with start delay 240  # optional: delay the first check by 4-minutes
set logfile syslog facility log_daemon

set alert
set mailserver
share|improve this answer

You could probably do the following in roots crontab:

10 * * * *      [ $(/bin/df --output=used /dev/diskid | /usr/bin/tail -1) -gt CHECKSIZE ] && /bin/mail -s "/dev/diskid Is to large" me@my.address

This command will basically automate checking the amount of used space, and if its bigger then CHECKSIZE will send you an email. It simply munges "df" to get the amount of disk used.

Realistically though, if you are going to be running multipler services/servers, you should look at Nagios - while it is a bit of a pain to set up, it is a great framework to check everything, all the time, with lots of free plugins. Most reputable companies would run it (or something equivalent)

share|improve this answer

You must log in to answer this question.

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