Monday, June 16, 2014

Script to find a keyword from a log file based on date and sends an email if found

 
On applnxsrv01, for ntdomain we are receiving STUCK threads on certain occasions.

Hence we request for a script to grep for the keyword 'STUCK' in the log file /wls//ntr/ntrUATDomain/logs/startntrPRDMServer1.log and send an email alert to the email address jay@expanor.local

bash-3.2$ cat /tmp/find_log_entry.sh
#!/bin/sh
# Jay; V.01; Mon Jun 16 12:10:10 EDT 2014
# This script will search for a keyword specified
# on the script and start looking at todays date and
# if there are any entries found, it will send
# an email to the user specified on the script.
#
grep $(date +"%b %d, %Y %r %Z") /wls/test/sfss/ntr/ntrUATDomain/logs/startntrUATMServer1.log 2>/dev/null| grep "STUCK"
if [ "$?" = 0 ]
then
#mail -s " Entry found on the log file on host `hostname`, please check .... " jay@expanor.local
echo "Keyword entry found on host `hostname` today that is `date`" | mail -s " Please check the message on body section" jay@expanor.local
fi
bash-3.2$


This is the log format
<Jun 4, 2014 4:33:25 PM EDT> <Info> <Management> <BEA-141107> <Version: WebLogic Server 10.3.6.0  Tue Nov 15 08:52:36 PST 2011 1441050 >
<Jun 4, 2014 4:33:26 PM EDT> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to STARTING>
<Jun 4, 2014 4:33:26 PM EDT> <Info> <WorkManager> <BEA-002900> <Initializing self-tuning thread pool>
 

No comments:

Post a Comment