Disk space monitoring & e-mail notifications with Bash

Running out of disk space is a common problem for unattended Linux boxes like database servers or backup storage servers. Usually I would use Zabbix (or Nagios) do to the monitoring, but it would be an overkill for a Raspberry Pi or a single NAS, so I made a small Bash script. This script runs df, checks disk usage and sends mail in case the free space is running low.

First of all the mail command must be configured properly in the system. I recommend installing ssmtp to handle outgoing mail. There are many tutorials on configuring ssmtp (a working SMTP account somewhere is also needed).

Configuration options at the beginning of the script are self-explanatory. The ignore option is helpful for mountpoints like CD drives (that always appear full). It won’t work for the / mountpoint due to the way the name is matched against the ignore list.

The script can be run every couple of hours from cron. It should not be run too often, because it will send mail every time it is executed if disk usage is too high. 🙂

Rate this post