Posts Tagged ‘Alert Notification script to warn you about low disk server space left on Linux / (Low Disk Space Notification via SMS and E-mail)’

Alert Notification script to warn you about low disk server space left on Linux / (Low Disk Space Notification via SMS and E-mail)

Thursday, June 10th, 2010

Once again I’ve encountered a problem with a non operational website on a CentOS Linux caused by a depleted disk space on the server.
The disk has been full with data to it’s maximum capacity because the last website SQL and file data backup.
To prevent future unexpected server outages caused by a filled up disk I’ve decided to implement a quick script to warn me when there is a low disk space left on the server system. I was lazy to write a disk monitoring script from scratch so I used the one present on Send an Email Alert When Your Disk Space Gets Low nice article.
I’ve done minor modifications to the script present on the article shown above to make it report on an email the exact system hostname from where it originates (helpful if you intend to run the script on more than one linux servers).
The script is also accustomed to send an SMS message to your mobile phone warning about the possible emerging disk full issues.

If you want to use my monitor_disk_space.sh script after the minor modifiations done to it to report server host and send sms to your mobile check here

Actually it seems too many old backups were just hanging there so I installed a tiny script on a crontab to periodically clear up the old backups.
Here is the script itself:

You can download the clear_old_log_backups.sh script here

Both the monitor_disk_space.sh and clear_old_backups scripts should be prepared to run on a crontab.
In case if you intend to run the aforementioned two scripts you would have to prepare a crontab records similar to the following:

# clear old data backups
30 2 2,20 * * /usr/sbin/clear_old_log_backups.sh
# monitor and report if disk space is low
05,30,59 4 * * * /usr/sbin/monitor_disk_space.sh

That two works fine for me hopefully they would be of use to somebody out there. Feel free to contact me here if you experience some problems in setting up the scripts.