#!/bin/ksh # # Author: David Morris # Version: $Id: disk-threshhold.ksh,v 1.2 2004/11/10 19:39:50 davey Exp $ # Purpose: # License: Released under the GNU Public Licence (GPL) # The terms of the GPL are available at: # http://www.gnu.org/licenses/gpl.html # # Usage: disk-threshhold.ksh # # Notes: # This script is designed to run at user specified periods from cron. # It will reset itself when ever the hour reaches $ResetHour and the # minutes are less than $ResetMinute. # # Set up variables we are going to use export Tempfile=/tmp/DiskThreshHold.tmp export Countfile=/tmp/DiskThreshHold.cnt export MaxCount=3 export Recipient=morrisd export ResetHour=08 export ResetMinute=20 export TimeNow=$(/bin/date +%H:%M) export HourNow=${TimeNow%:*} export MinuteNow=${TimeNow#*:} export DiskThreshHold=94 export Uname=$(/bin/uname) export Hostname=$(/bin/hostname) export ExcludeFromCount='^Filesystem ^mvfs ^proc /mnt' export GREP=/usr/xpg4/bin/grep export AWK=/usr/bin/awk export RM=/usr/bin/rm export CAT=/usr/bin/cat export MAILX=/usr/bin/mailx export DF=/usr/sbin/df export TOUCH=/usr/bin/touch case $Uname in AIX) # Extract the correct fields from AIX df export AwkCmd="awk '{print \$4 \$7}'" ;; SunOS) # Extract the correct fields from Solaris df export AwkCmd="awk '{print \$5 \$6}'" ;; *) echo "Operating system: $Uname not supported!" exit ;; esac # If the $HourNow is equal to $ResetHour then remove the $Countfile # to reset the count of mails sent if [ $HourNow -eq $ResetHour ] then $RM $Countfile fi # The $Countfile keeps track of $Count to determine how many # times the program has run. It stops you getting hundreds of # mail messages about the same incident. if [ ! -r $Countfile ]; then $TOUCH $Countfile echo 1 > $Countfile fi >$Tempfile for i in $($DF -k | $GREP -Ev "$ExcludeFromCount" | $AWK '{print $5 $6}' | $AWK -F% '{print $1 ":" $2}') do LEFT=${i%:*} RIGHT=${i#*:} if [ $LEFT -gt $DiskThreshHold ] then echo "WARNING: Filesystem $RIGHT at ${LEFT}% capacity" >> $Tempfile ; fi done $GREP "^WARNING: Filesystem" $Tempfile Warnings=$? Count=$($CAT $Countfile) function SendResult { if [ $Warnings -eq 0 ] then $CAT $Tempfile | $MAILX -s "${Hostname}: Filesystem" $Recipient Count=$((Count+1)) echo $Count > $Countfile else exit fi } if [ $Count -lt $MaxCount ] then SendResult else echo "Exiting because MaxCount Threshold ($MaxCount) has been reached!" echo "No mail will be sent to $Recipient !" fi rm $Tempfile