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:

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

if [ $freespace -lt 12288 ];
echo "HDD freespace - "$freespace"Mb"
(echo "Subject:HDD freespace - "$freespace"Mb on $HOSTNAME"; echo "HDD freespace - "$freespace"Mb on $HOSTNAME";) | sendmail

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

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

Leave a comment

Leave a Reply