Logfile monitor script

Hi,

I'm trying to write a logfile monitor script that reads the logfile and then emails out once there is an error with SQL in. Here is my attempt below which does not work. I'm not much of a scripter as you can probably see but some pointers in the right direction would be much appreciated.

DATE=`date`
DATE1="`date +%b` `date +%e` `date +%H`:`date +%M`"
HOST=`hostname`
LOG=/var/adm/sqllog
ERRORLOG=/home/sql/sqlerrlog
 
tail -f $LOG |
while true
do
  sleep 10
  read line
  echo "$line" | grep "$DATE1" | grep SQL > $ERRORLOG
done
 
if test -s $ERRORLOG; then
  mail -s "SQL errors in $LOG on $HOST $DATE" "me@host.com" < $ERRORLOG
fi

You can try something like this , if you want to check for errors :

DATE=`date`
DATE1="`date +%b` `date +%e` `date +%H`:`date +%M`"
HOST=`hostname`
LOG=/var/adm/sqllog
ERRORLOG=/home/sql/sqlerrlog
 
while true
do
tail -100 $ERRORLOG | grep  "ORA"  > /dev/null
if [ $? -eq 0 ];then
mail -s "SQL errors in $LOG on $HOST $DATE" "me@host.com" 
exit
fi
done

Cheers for the reply, what i'm looking for is to make sure the the alert i'm sending an email for has just happend which is why I wanted to try use the $DATE1 = Nov 4 11:29 which is the same format as in the logfile. But If I try it doesn't work. Is it possible to grep twice from the output of a tail and direct it to /dev/null?

DATE=`date`
DATE1="`date +%b` `date +%e` `date +%H`:`date +%M`"
HOST=`hostname`
LOG=/var/adm/sqllog
ERRORLOG=/home/sql/sqlerrlog
 
while true
do
  tail -100 $LOG | grep "$DATE1" | grep "SQL" > /dev/null
if [ $? -eq 0 ];then
  mail -s "SQL errors in $LOG on $HOST $DATE" "me@host.com" 
  exit
fi
done

Is it the code you posted not working ?..

check whether you have the data that matches the criteria "SQL" and

"$DATE" in the "sqlerrlog" file or not .