Script to check the free space on the HDD

Usually I use Zabbix to monitor free space on the disk system, which also notifies when it is running out, but Zabbix is not used on some servers, so I wrote a small script that performs this check and sends an email notification, for example, if there is less than 12Gb of free memory:

#!/bin/bash
freespace=`df -m | grep "/dev/sda1" | awk '{print $4}'`

if [ $freespace -lt 12288 ];
then
echo "HDD freespace - "$freespace"Mb"
(echo "Subject:HDD freespace - "$freespace"Mb on $HOSTNAME"; echo "HDD freespace - "$freespace"Mb on $HOSTNAME";) | sendmail test@ixnfo.com
fi

The script added to /etc/crontab to execute every 3 hours:
* */3 * * * root /scripts/hdd_freespace.sh > /dev/null 2>&1

See also my articles:
Zabbix installation on Ubuntu from distribution packages
Using and configuring CRON
Script to delete old files

Did my article help you? How about buying me a cup of coffee as an encouragement? Buy me a coffe.

Leave a comment

Leave a Reply