Here’s a simple shell script that will check the available disk space on the root filesystem and send an e-mail message if the used space is at 90% or more.

#!/bin/bash
# monitor available disk space
SPACE=`df | sed -n ‘/\/$/p’ | gawk ‘{print $4}’ | sed ’s/%//’`
if [ $SPACE -ge 90 ]
then
echo “Disk space on root at $SPACE% used” | mail -s “Disk warning” email@example.com
fi

you can set the shell script to execute at a set number of times to monitor the disk activity. You can do this using the cron. For a low-volume file server, you may only have to run the script once a day:

30 0 * * * /usr/local/scripts/diskmon

For a high-volume file server environment, you may have to monitor this every 30mins.

/30 * * * * /usr/local/scripts/diskmon

Like this blog? Why not buy me a cup of coffee?