check_disk_usage.sh

Quick and dirty way to get an alert before your server starts to go crazy because of a full disk.

This script checks if a disk is more than 75% full.

#!/bin/bash

df -h | awk '/%/ {
        limit = 75
        percent = sprintf("%d",$5)
        if ( percent > limit ) {
                print "Warning: ",$6," (",$1,") is to ",percent,"% full:"
                print $0
        }
}'

Save it under /root/check_disk_usage.sh and create the following crontab entry to check the disk usage every day at half past midnight.

30  0  *   *   *     /root/check_disk_usage.sh

Assuming your host has configured an MTA and defined a recipient for root@<yourhost>, you should get an e-mail whenever a disk is more than 75% full.

blog comments powered by Disqus