2 min read
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.
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:
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.