- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Monitoring a Log File
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:01 AM
12-11-2003 05:01 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:05 AM
12-11-2003 05:05 AM
Re: Monitoring a Log File
Try
tail logfile | grep "error occured" > otherfile
As a start point
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:09 AM
12-11-2003 05:09 AM
Re: Monitoring a Log File
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:11 AM
12-11-2003 05:11 AM
Re: Monitoring a Log File
I will have to embarass you if I get an email from your system... :-)
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:12 AM
12-11-2003 05:12 AM
Re: Monitoring a Log File
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:13 AM
12-11-2003 05:13 AM
Re: Monitoring a Log File
look here:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=293706
greetings,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:14 AM
12-11-2003 05:14 AM
Re: Monitoring a Log File
I was just giving pointers, you gave the solution.
;^)
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:16 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:17 AM
12-11-2003 05:17 AM
Re: Monitoring a Log File
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:21 AM
12-11-2003 05:21 AM
Re: Monitoring a Log File
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 05:29 AM
12-11-2003 05:29 AM
Re: Monitoring a Log File
That script has saved me from two production problems this year.
The kudos are better than points.
My script is run daily via cron. For your situation you'll want to run it probably several times an hour. If you lose networking, it obviously won't help much.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 09:38 AM
12-11-2003 09:38 AM
Re: Monitoring a Log File
I have a small question here. If my script is waiting for the string "Error Occured" indefinitely, will it create any perfornmance problem in the system? Because I want to run this script 24 * 7 * 365.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 09:42 AM
12-11-2003 09:42 AM
Re: Monitoring a Log File
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 09:49 AM
12-11-2003 09:49 AM
Re: Monitoring a Log File
If your system totally halts, everyone is going to notice and the script is no good.
If you run it once a minute and an error occurs with a DNS server and you get hundreds of errors, you are going to have a mailbox problem. Its going to be very full.
If you really want continuous monitoring then you will probably want the script to set a flag after it detects and error. Say change a data file in /etc from 0 to 1. When it picks up errors it makes a decision about doing a duplicate email, and only tries that say once a day.
Running the script too often is likely to burn too much resources.
If the system is mission critical(mine are) and you can't even tolerate 10 seconds of non-resopnse, then run it regularly or consider other kinds of monitoring tools like scm.
The script I uploaded only runs once a day. Its looking for bad disk drives and if it finds one, it runs another program that checks out all the disks. I'm attaching that as a reference because its useful as well.
Good Luck, thanks for the compliments and the points.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 09:59 AM
12-11-2003 09:59 AM
Re: Monitoring a Log File
I am actually using the following script and it is just fine for my purpose(writing all errors to another log). I want it to run 24*7. If I run this in the background forever is it ok? If I want to kill it(running in the background) how do I do it?
Thanks.
*******
tail -f log.txt | while read LINE
do
echo $LINE | grep "Error Occured" >> log2.txt
done
**********
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 04:28 PM
12-11-2003 04:28 PM
Re: Monitoring a Log File
SEP> 41228.sh
SEP> :
SEP> /usr/sbin/dmesg | grep lbolt > /tmp/checkwardware
SEP> errs=`wc -l /tmp/checkwardware | awk {'print $1'}`
nit picking.... since the tmp file is only used to count lines from,
How about replacing the above two lines form the suggested script by this one:
/usr/sbin/dmesg | errs=`grep -c lbolt`
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 08:47 PM
12-11-2003 08:47 PM
Re: Monitoring a Log File
I have tested it. This script takes absolutely no cpu resources whatsoever, while waiting for a line. Tail -f is like a programme waiting for an input from stdin and the user is drinking his coffee. ;-) So you can run it 24 hours per day without problems.
have fun here,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2003 08:50 PM
12-11-2003 08:50 PM
Re: Monitoring a Log File
If you do it manually, do a ps -ef | grep yourscriptname.
Then kill -9 pid.
have fun,
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2003 06:05 AM
12-12-2003 06:05 AM
Re: Monitoring a Log File
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2003 01:00 PM
12-12-2003 01:00 PM
Re: Monitoring a Log File
I have a small problem here!
I am trying to capture the line that has the "Error Occured" string
tail -f log.txt | while read LINE
do
var= `echo $LINE | grep "Error Occured"`
echo $var
done
Apart from assigning the line to the variable var, list of files in the working directory is also added to $var. What am I doing wrong here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2003 01:06 PM
12-12-2003 01:06 PM
Re: Monitoring a Log File
var= `echo $LINE | grep "Error Occured"`
There is an extra space after var=
it should read,
var=`echo $LINE | grep "Error Occured"`
-Karthik S S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2003 02:40 PM
12-12-2003 02:40 PM
Re: Monitoring a Log File
Did you try the one with no space. I also tried this and this too gives the same result!
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2003 09:01 AM
12-14-2003 09:01 AM
Re: Monitoring a Log File
I found it! At the end of the line(ie. $LINE ) of "Error Occured" string there was a " * " . So grep was listing all the files in the directory! What a sigh of relief!
Thanks guys!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2003 07:50 AM
12-16-2003 07:50 AM
Re: Monitoring a Log File
I am trying to change the same monitoring ksh script into perl script. Can this be converted in perl script? Also Is it possible to mix perl script and shell script?
Thanks for the great help!
**********
tail -f log.txt | while read LINE
do
var= `echo $LINE | grep "Error Occured"`
echo $var
done
***********
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2003 12:31 PM
12-16-2003 12:31 PM
Re: Monitoring a Log File
Thanks.