How to setup the email alert for low disk space?

If you don't want to setup to a full monitoring solution such as Nagios you can create your own scripts for monitoring the disk space. The following script alerts you when the root partition of server is almost full:

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

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

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

@daily ~/disk_space_alert.sh

Was this answer helpful?

 Print this Article

Also Read

How to install ZendOpcache on CentOS?

The Zend OpCache provides faster PHP execution through opcode caching and optimization. It...

How to setup PPTP VPN?

A Point-To-Point Tunneling Protocol (PPTP) allows you to implement your own VPN very quickly, and...

How to install Memcached on CentOS?

Memcached is very fast caching system for MySQL. It is a distributed, high-performance, in-memory...

[/url]memcached.so missing - Memcached installation error

While Memcached installation on Centos server, I was getting the error as '[/url]memcached.so...

Disk Usage Useful Command

Note - You can replace /home with correct '/' drive on your server. 1. Checking the disk usage -...

Powered by WHMCompleteSolution