[cciug] Detecting full / nearly full hard disks

From: Stephen Holmes (sholmes@atlan-tech.com)
Date: Tue Feb 29 2000 - 08:37:13 EST


This script does the job as once.
We run it regularly from Cron.

The script is mounted in a central location, so the first part sorts out which
server it is running on. It then sets up the yellow and red alerts.

We don't E-mail, preferring to splat messages onto the console for yellow
alerts, and various other screens for red.
You could easily invoke mailx or similar to mail things out.

Chop it up at your leisure.

#!/bin/sh
#
# Warn when thresholds are exceeded on selected disks
#
HOST=`uname -n`
DATE=`date +%H:%M`

# MONITORED_DISKS is a space separated sequence of triples.
# each triple comprises mountpoint:warning_threshold:panic_threshold
if [ $HOST = "spock" ]
then
     MONITORED_DISKS="/ext0:90:98 /ext1:90:93 /ext2:90:93 /ext3:90:93
/ext4:90:93"
elif [ $HOST = "kirk" ]
then
     MONITORED_DISKS="/ext0:96:97 /ext1:90:93 /ext7:90:93"
elif [ $HOST = "khan" ]
then
     MONITORED_DISKS="/ext0:90:93 /ext1:90:93 /ext2:90:93 /ext3:90:93
/ext4:90:93 /ext6:90:93"
elif [ $HOST = "daystrom" ]
then
     MONITORED_DISKS="/opt:93:96 /ext0:90:93 /ext1:90:93 /ext2:90:93 /ext3:90:93
  /ext4:90:93 /ext5:90:93"
elif [ $HOST = "pod" ]
then
     MONITORED_DISKS="/ext0:90:93 /ext1:90:93 /ext2:90:93 /ext3:90:93
/ext4:90:93 /ext5:90:93 /ext6:90:93 /ext7:90:93"
elif [ $HOST = "tardis" ]
then
     MONITORED_DISKS="/ext0:90:93 /ext1:90:93 /ext2:90:93 /ext3:90:93
/ext10:90:93 /ext11:90:93 /ext12:90:93 /ext13:90:93"
fi

for diskspec in $MONITORED_DISKS
do
     mount=`echo $diskspec | cut -f1 -d:`
     threshold=`echo $diskspec | cut -f2 -d:`
     panic=`echo $diskspec | cut -f3 -d:`

     line=`df -k $mount | grep $mount`
     perc=`echo $line | awk '{ print $5 }'`
     cap=`echo $perc | cut -f1 -d%`

     if [ $cap -gt $threshold ]
     then
          free=`echo $line | awk '{ print $4 }'`

          echo "$HOST $DATE Disk Warning: $mount is $perc full. $free Kbytes
remain" > /dev/console

          if [ $cap -gt $panic ]
          then
               ##
               ## Alert all guys who can fix the situation
               ##
               for name in dgrierso jsteele alanl markl kennym sholmes ehattie
               do
                    /usr/bin/write $name <<Z
$HOST $DATE Disk Warning: $mount is $perc full. $free Kbytes remain
Z
               done
          fi
     fi
done

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



This archive was generated by hypermail 2b29 : Sun May 06 2001 - 00:23:31 EDT