Automatic Emails For Full Drives In Debian

I have a VPS which I use for storing backups and running some of my projects. This VPS recently filled up, leading to lots of problems. I went looking for a solution which would email automatically whenever a drive starts getting full.


I found a bash script online which I modified a bit; I added the hostname to the email is sends and set a lower threshold than the original script. Here is what I ended up with in ~/

CURRENT=$(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%


Then I added this to the crontab;

0 0 * * 0       root    bash /root/