1752781 Members
6431 Online
108789 Solutions
New Discussion юеВ

Monitoring a Log File

 
SOLVED
Go to solution
dude70_1
Advisor

Monitoring a Log File

Hi Guys,

I need to monitor at the end of a logfile using a korn script continuously for a particular phrase to occur. Like "Error Occured" then I have to read the whole line and write to another file. Can you guys provide me any help!

Thanks in advance!
Dude70
24 REPLIES 24
Paula J Frazer-Campbell
Honored Contributor

Re: Monitoring a Log File

Hi

Try

tail logfile | grep "error occured" > otherfile

As a start point

Paula
If you can spell SysAdmin then you is one - anon
Paula J Frazer-Campbell
Honored Contributor

Re: Monitoring a Log File

A little more

Create a file called monitorlog containing:-


--------------cut-----------------
#!/bin/sh
tail logfile | grep error occured > otherfile
sleep 10
exec monirorlog
----------------cut--------------

this will check the file and write out the error to otherfile, sleep for 10 seconds and then restart itself.

Paula

HTH

Paula
If you can spell SysAdmin then you is one - anon
Steven E. Protter
Exalted Contributor

Re: Monitoring a Log File

Modify the attached script, point it to the log you want to monitor, change lbolt to error or whatever and don't forget to change the email address.

I will have to embarass you if I get an email from your system... :-)

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
dude70_1
Advisor

Re: Monitoring a Log File

Thanks Paula,

Thing is the log file is dumped with lots of errors some times. I don't want to read the same error again. I want to start from the point where I finished reading before.

Thanks.
Michael Schulte zur Sur
Honored Contributor

Re: Monitoring a Log File

Paula J Frazer-Campbell
Honored Contributor

Re: Monitoring a Log File

Neat script Steven,

I was just giving pointers, you gave the solution.

;^)


Paula
If you can spell SysAdmin then you is one - anon
Paula J Frazer-Campbell
Honored Contributor
Solution

Re: Monitoring a Log File

Hi

Can you post an example of the log file?

Paula
If you can spell SysAdmin then you is one - anon
Michael Schulte zur Sur
Honored Contributor

Re: Monitoring a Log File

Hi Dude70,

this is the script from the thread from Bryan:
tail -f log.txt | while read LINE
do
echo $LINE | grep "Error Occured" >> log2.txt
done

greetings,

Michael
John Carr_2
Honored Contributor

Re: Monitoring a Log File

how about this

tail -f logfile | grep my_error

tail will keep waiting on the logfile and feed new lines to grep as they occur continuing until you kill the process.

John.