Need to script following a noisy log file which rolls over


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to script following a noisy log file which rolls over
# 1  
Old 06-29-2009
Need to script following a noisy log file which rolls over

I'd like to write a script or even a good command line that can follow a very noisy log file looking for specific patterns but can also handle log roll overs in an intelligent way.

I sometimes do something like the following:

# tail -f /var/log/crazy.log | grep 'ailure' > /my/dir/crazy-failures.log

But then after some time the log will automatically roll over due to newsyslog...

Jun 28 00:00:00 qa-arc1-1 newsyslog[36074]: logfile turned over

At which that the server no longer logs messages to that file and my command no longer filters out lines with 'ailure'.

I guess one way to attack it would be to programatically search for 'logfile turned over' and automatically switch to the new log file. Is that the best option? Any suggestions?

Thanks!

---------- Post updated at 10:38 PM ---------- Previous update was at 10:31 PM ----------

I should also mention that I believe there are cases when the log file will roll over for reasons other then just hitting midnight i.e. reaching some size limit. Part of the reason I want to do this is that the default configuration will only roll over a log like 3 times before destructively removing the old log files. And the log file is to noisy to extend beyond that, anyway.
# 2  
Old 06-29-2009
Example how to control child process.
logreader is our logreader and mainlogreader controll subreaders.

Code:
#!/usr/bin/ksh
# logreader.sh
f=/var/log/crazy.log 

function look()
{
   tail -f $f | while read line
   do
        case "$line" in
                *ailure*) do_something ;;
        esac
   done
}
#--main---
look

And main process, control subreaders
Code:
#!/usr/bin/ksh
# mainlogreader.sh
f=/var/log/syslog.log 
child=""

function start
{
    ./logreader.sh >> somelogfile.log 2>&1  &
    #save childprocess pid
    child=$!
}

function restart
{
    # stop child process using signal 15 
    kill $child
    # wait child exit signal
    wait $child
    # restart
    start
}

function look
{
   tail -f $f | while read line
   do
        case "$line" in
                *"logfile turned over"*) restart ;;
        esac
   done
}

####################################
#MAIN
####################################
# start sub logreader
start
# start my log reading
look

And now start
./mainlogreader.sh
or background process
./mainlogreader.sh > log.txt 2>&1 &
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

2. Shell Programming and Scripting

Script to rotate file log

Hi Experts, I have script on crontab and give output quite large. I would like to know how to create rotate log when the size of log maximum 50MB if the test.log is 50MB then create test.0 Thanks Edy (2 Replies)
Discussion started by: edydsuranta
2 Replies

3. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

4. Shell Programming and Scripting

Shell Script to grep Job File name and Log File name from crontab -l

Hello, I am new to shell scripting. I need to write a shell script where i can grep the name of file ie. .sh file and log file from crontab -l. #51 18 * * * /home/oracle/refresh/refresh_ug634.sh > /home/oracle/refresh/refresh_ug634.sh.log 2>&1 #40 17 * * * /home/oracle/refresh/refresh_ux634.sh... (1 Reply)
Discussion started by: guptra
1 Replies

5. Shell Programming and Scripting

Script to monitor log file

Hi, Have written a script to monitor linux non standard log file based on line numbers, so each check store $otalinenum .. then in next check after 10 minutes it compre the current_total_line_num > last_total_line_num then it will parse the log file from last_total_line_num to... (0 Replies)
Discussion started by: Shirishlnx
0 Replies

6. HP-UX

Script to monitor /var/opt/resmon/log/event.log file

AM in need of some plugin/script that can monitor HP-UX file "/var/opt/resmon/log/event.log" . Have written a scrip in sh shell that is working fine for syslog.log and mail.log as having standard format, have interrogated that to Nagios and is working as I required . But same script failed to... (3 Replies)
Discussion started by: Shirishlnx
3 Replies

7. Shell Programming and Scripting

log file script

I have a log which is configured as follows: date time code1 notes: code2 A monthly job is run based on information supplied from this log. The end of each monthly job is clearly indicated by a code within 'code1'. At this time someone is performing a less on the log, moving to the end,... (2 Replies)
Discussion started by: bwatlington
2 Replies

8. UNIX for Dummies Questions & Answers

Script for parsing details in a log file to a seperate file

Hi Experts, Im a new bee for scripting, I would ned to do the following via linux shell scripting, I have an application which throws a log file, on each action of a particular work with the application, as sson as the action is done, the log file would vanish or stops updating there, the... (2 Replies)
Discussion started by: pingnagan
2 Replies

9. UNIX for Dummies Questions & Answers

Log file for a Script

Oracle92 on solaris 8. We have a Truncate Script that runs every night to cleanup certain tables , so new data gets loaded into. This Script is run in Unix Shell script where i set Environment varibles, and things like that.. Now, how do i create a log file of the script , to see weather the... (3 Replies)
Discussion started by: vr76413
3 Replies
Login or Register to Ask a Question