Monitor disk space for a given set of mount points

posted Apr 23, 2012, 5:10 PM by Sachchida Ojha


#!/bin/bash
mntlist="/home /tmp /"
for ml in $mntlist
do
echo $ml
usedSpc=$(df -h $ml |awk '{print $5}' | grep -v capacity | cut -d "%" -f1 -)
BOX=$(uname -a |awk '{print $2}')
#
case $usedSpc in
[0-9])
arcStat="Relax, lots of diskspace: $usedSpc"
;;
[1-7][0-9])
arcStat="Disk space OK: $usedSpc"
;;
[8][0-9])
arcStat="space getting low: $usedSpc"
;;
[9][0-9])
arcStat="warning, running out of space: $usedSpc"
echo $arcStat $ml | mailx -s "space on: $BOX" snojha@gmail.com
;;
[1][0][0])
arcStat="update resume, no space left: $usedSpc"
echo $arcStat $ml | mailx -s "space on: $BOX" snojha@gmail.com
;;
*)
arcStat="huh?: $usedSpc"
esac
#
BOX=$(uname -a | awk '{print $2}')
echo $arcStat
#
done
#
exit 0



Comments