Send an Email Alert When Your Disk Space Gets Low

Posted: 15 octombrie 2009 in Cum Sa ..., Uncategorized

If you don’t want to step up to a full monitoring solution such as Nagios you can create your own scripts for monitoring the things that you want to monitor, such as disk space. The following script alerts you when your root partition is almost full:

#!/bin/bashCURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')\
if [ "$CURRENT" -gt "$THRESHOLD" ] ;
then   mail -s 'Disk Space Alert' <<
EOF "Your root partition remaining free
space is critically low. Used: $CURRENT" EOF

The script sends an email when the disk usage rises above the percentage specified by the THRESHOLD varialbe (90% here).

To run it daily, for example, save the script to the file in your home directory, change the email to your email, and add the following line at the end of /etc/crontab file:

@daily ~/

Comentariile sunt închise.