#! /bin/ksh # # $0 = errmon.sh # # Written 11/3/1998 Bill Verzal. # # This script will run every [interval] and check the error log # for new entries. Upon finding them, it will send an email to # administrators containing a message indicating the change # in errlog status, as well as the offending lines. # if [ "$1" = "-v" ] ; then set -x fi if [ "$1" = "-k" ] ; then p=`ps -ef|grep errmon|grep -v grep|grep -v "\-k"|awk {'print $2'}` if [ "$p" != "" ] ; then echo "Killing process $p\n" kill -9 $p fi exit 0 fi interval=60 # Divide interval by 60 to get number of minutes. me="$0 - Hardware error monitoring" myname=`hostname` args="$*" mailto="root" boj=`date` tc=`errpt -dH,S,U,O | wc -l` lc="$tc" date=`date +%Y%m%d` maxhits=20 hits=0 # lc="last count" # tc="this count" echo "$me started.\nThis message goes to $mailto." | mail -s "Errlog monitoring for $myname" $mailto logger "$0 started" while : ; do tc=`errpt -dH,S,U,O | wc -l` if [ "$lc" -lt "$tc" ] ; then foo=`expr $tc - $lc` foo=`expr $foo - 1` if [ "$foo" -eq "0" [ ; then foo=1 fi msg="$foo new errors have been found on $myname" hits=`expr $hits + $foo` if [ "$hits" -ge "$maxhits" ] ; then sub_message="Error log has been automatically cleared due to the number of errors" msg="$msg - $sub_message" fi errlogl=`errpt -dH,S,U,O -a` logger $msg msg=" $msg \n Errlog details below:\n $errlogl \n" echo "$msg" | mail -s "Errlog status change on host $myname" $mailto if [ "$hits" -ge "$maxhits" ] ; then cp -p /var/adm/ras/errlog /var/adm/ras/errlog.$date errclear 0 hits=0 tc=0 fi fi lc="$tc" sleep $interval done