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. :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|