Shell script to monitor weblogic log for exception

Summary:

This script is going to monitor weblogic AdminServer.log to for any Exception and trigger email with exception stack.

WeblogiServerLogWatcher.sh:

=====================

#!/bin/bash
#set -xv
# The script to verify the error from AdminServer.log logs

Path=/scratch/Oracle/Middleware/user_projects/domains/Testing/servers/AdminServer/logs

#removing the old scripting logs
if [ -s “$Path/script/file.txt” ]
then
rm $Path/script/file.txt
fi

#date based on the log format
date=`date “+%b %-d, %Y”`

#Log Details
log1=$Path/AdminServer.log

#checking logs
grep -i “$date” $log1 | egrep -A20 -B5 -i ‘Exception’ >> $Path/script/file.txt

#email

if [ -s “$Path/script/file.txt” ]
then
#echo ‘file has data’
cat $Path/script/file.txt | mail  -s “Exception in Weblogic Server” sxyz@oracle.com,xrct@gmail.com
# do something as file has data
#else
# do something as file is empty
fi

#cat $Path/script/output | mail  -s “Exception in Weblogic Server” sxyz@oracle.com,xrct@gmail.com

# END

===================================

Add it to Cron job:

Type the below command

crontab -e

Add the below line to run the script for every 4 hours

0 */4 * * * /scratch/Oracle/Middleware/user_projects/domains/Testing/servers/AdminServer/logs/script/WeblogiServerLogWatcher.sh

Summary:

Above script I wrote for internal use, please customize according to your need. You can monitor multiple servers and also read email from external file etc.

About sasikumarchellappan

Part of Sustaining Weblogic Development Team of Oracle Weblogic Server.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment