getting help on finding exception in running log file

Hi all,

I am trying to write a script for an application server log file where i want to put this script as a cron tab entry and it will check the server log file last 1000/500 line for every fifteen minute.

i am using the script like this.

count=`tail -n 1000 Trace.log | grep -c 'JmsTimeOutException'`
if [ $count -ne 0 ]
then
echo "Error! $server is thrown JmsTimeOutException $(date +"%d-%b-%y at %X %Z")" > temp.txt
cat temp.txt | mail -s "Error! $server is thrown JmsTimeOutException $(date +"%d-%b-%y at %X %Z")" $mailid
rm temp.txt
fi

Now the problem is i need to check many exception and i want to mail that. I'm repeated the same code again and again in the script for every exception. i feel that i am following some wrong logic and trying tail the log again and again for each exception. Please suggest me some better think that i can use.

Thanks
Senthilkumar.

you could put each pattern that you wish to search for in a file, one per line, and use grep -f option. -f is specified by posix, so should be available on most versions of grep.

count=`tail -n 1000 Trace.log | grep -c -f /home/user/patterns`