Free space on system partitions are very important.

We may get several problems if /usr /var /tmp or / partition run out of disk space.

I have created one simple shell script to check the percentage space used on different drive and sent a notification if any of partition usage exceeds the 90% you can modify it as pre needs and requirement.

#!/bin/bash

################################################ #
# disk space usage alert #
################################################ #

df -h | grep -v ‘Use’ | awk ‘{print $5″ : “$6}’ | replace ‘%’ ” > /tmp/disk-percent

for i in `cut -f 1 -d : /tmp/disk-percent`

do

if [ $i -ge "90" ];

then

echo partition `grep $i /tmp/disk-percent | cut -f 2 -d :` running out of disk space on `hostname` >> /tmp/disk-warning

fi

done

if [ -f /tmp/disk-warning ];
then

mail -s “URGENT `hostname` running out of disk space” administrator@mazhar.co.in /tmp/disk-percent

with

df -h | grep -v ‘home\|Use’ | awk ‘{print $5″ : “$6}’ | replace ‘%’ ” > /tmp/disk-percent

Create a file say /home/disk-monitoring.sh give executable permissions and add a cron to execute it after specific time intervals (say 3 hours)

0 */3 * * * /home/disk-monitoring.sh