Fist we need a shell script that does the checking:

ADMIN="admin@youradress.com"
ALERT=80
df -H | grep -vE "^[^/]|tmpfs|cdrom" | awk '{ print $5 " " $1 }' | while read output;
do
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  if [ $usep -ge $ALERT ]; then
    echo "Disk space alert: \"$partition ($usep%)\" on $(hostname) as on $(date)" |
     mail -s "Alert: Almost out of disk space $usep" $ADMIN
  else
    echo "Drive \"$partition ($usep%)\" is has enough space left"
  fi
 
done

 

Then as your system trys to mail you the alert and the mailutil is not install. install it using:

sudo apt-get install mailutils

Now configure mail using ssmtp

Install and configure sstmp

sudo apt-get install ssmtp

sudo nano /etc/ssmtp/ssmtp.conf

Uncomment FromLineOverride=YES by deleting the #

Add those lines for using gmail as an email server

AuthUser=<user>@gmail.com
AuthPass=Your-Gmail-Password
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES

 

now the script should be working

Leave a comment

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close