Operating System - HP-UX
1836417 Members
2622 Online
110100 Solutions
New Discussion

Re: Script to monitor logs for errors at specific time.

 
SOLVED
Go to solution
Gulam Mohiuddin
Regular Advisor

Script to monitor logs for errors at specific time.

The log file is /psoft/hrprod/appserv/HR88/LOGS/APPSRV_0309.LOG

I want to monitor the error message "Java exception thrown" in this log between 7:00 AM to 5:00 everyday.

Following is one example line from that log file:

PSPPMSRV.8442 [03/09/06 09:12:38](1) (JNI): Java exception thrown: java.net.SocketTimeoutException: Read timed out

I want to check this condition for every one minute through Cron.

If this error message exists between 7:00 AM to 5:00 PM then send me alert email.

The time between 7:00 AM to 5:00 can be checked from position 26-30 for example ([03/09/06 09:12:38]).

Thanks in advance for your anticipated help.

Regards,

Gulam.
Everyday Learning.
3 REPLIES 3
Carlos Roberto Schimidt
Regular Advisor

Re: Script to monitor logs for errors at specific time.

Hi,

Run each hour in cron:

DATE=`date "+%m/%d/%y"`
CUR_HOUR=`date "+%H:"`
MSG_ERROR="Java exception thrown"

sendmail_function ()
{
##Write here your command to send email
sendmail email@domain.com }
grep $DATE logfile | egrep $MSG_ERROR | grep "$CUR_HOUR >/tmp/check.log

if [ $? -ne 0 ] ; then
sendmail_function
fi


Arturo Galbiati
Esteemed Contributor
Solution

Re: Script to monitor logs for errors at specific time.

Hi Gulam,
put in cron a script which run evey minutes:

awk '/Java exception thrown/&&substr($0,28,2)+0>=7&&substr($0,28,2)+0<=17' psoft/hrprod/appserv/HR88/LOGS/APPSRV_0309.LOG|mailx -s "Java exception thrown detected at $(date +%Y%m%d' '%H:%M) on $(hostname)"

This script assumes that 5:00PM are 17:00.

HTH,
Art
Gulam Mohiuddin
Regular Advisor

Re: Script to monitor logs for errors at specific time.

Thanks Arturo Galbiati.

Good script, that's what I was looking for.

Really appreciate it.

Regards,

Gulam.
Everyday Learning.