Not so generic way to check ‘any’ logfile for erros
I have written at least about 5 variations of this same script. Some more flexible and genereal purpose.
But in the end I have been writing customs made out of this skel.
What usually needs change: date formatting, key errors.
#!/bin/bash # script to check how many key in the current hour # Felipe Ferreira June 2012 # updated April 2013 #important to check your log date/time stamp format, it changes from log to log so you will need to get it right #if you are interested in only getting statistics, its better to use last hour, this way you have consistent number #if you need to get the error right when it happens its better to use the now hour #possible bugs: it will keep showing that you have an error for an entire hour... DIA=`date +%d` MES=`date +%b` HORA=`date +%H` #HORA=`date +%H -d "1 hour ago"` #ultima hora tday="$MES $DIA $HORA" KEY="OutOfMemoryError" LOGFILES="/opt/tibco/tra/domain/PRD/application/logs/*.log" if [ "$2" == "" ] then echo -e "\n Syntax: $0
\nex.: $0 50 900 \n O script retoran a qunatidade de erros nesta hora \n" exit 3 fi warn=$1 crit=$2 #debug #echo "DATE: $tday" #echo "grep $tday $LOGFILES |grep -c $KEY" ERROS=`grep "$tday" $LOGFILES |grep -c "$KEY"` MSG="Existem $ERROS erros do tipo $KEY as $HORA horas|ERROS=$ERROS" if [ $ERROS -ge $crit ]; then echo "CRITICAL - $MSG" exit 2 elif [ $ERROS -ge $warn ]; then echo "WARNING - $MSG" exit 1 else echo "OK - $MSG" exit 0 fi