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 perform LAMP installation on CentOS?

LAMP stands for Linux, Apache, MySQL, and PHP. It is nothing but Linux operating system with...

Basic exim commands

1. REMOVE MAILS BY ID - /usr/sbin/exim -v -Mrm (MAIL ID HERE) 2. LIST QUEUED MAILS -...

Daily Useful Linux Commands

Finding the username from provided hosting service name - /script/whoowns domain_name Finding...

Disk Usage Useful Command

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

How to backup and restore large MySQL databases using mysqldump?

1. Backup database:#mysqldump -u username -p[username_password] databasename >...