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 ~/send_email_if_drive_full.sh

#!/bin/bash
CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
THRESHOLD=75

if [ “$CURRENT” -gt “$THRESHOLD” ] ; then
mail -s ‘Disk Space Alert’ chris.j.trowbridge@gmail.com << EOF
vps1.cjtrowbridge.com
Your root partition remaining free space is critically low. Used: $CURRENT%
EOF
fi

 

Then I added this to the crontab;

0 0 * * 0       root    bash /root/send_email_if_drive_full.sh