Loop script required within an active log file

I need some help please...

This is the scenario what I am sitting with.

1 - I am kicking of a batch script.
2 - This batch script is writing to an active log file which is also use by other batch scripts.
3 - I need to monitor this active log file and grep for the script name as well as the status of the script as soon as it ends.
4 - There will be other scripts writing to this active log file which will have a status as well when ending.

So, the idea is to have the following:
1 - A script that will view the active log file, which is called from command line: "viewlog"
2- grep for the "script name" and the "status" and the "status code" whithin the same line
3 - Script need to exit with the "status code" that is produced within this active log file.

Here is an example of the active log file lines, the highlighted line is the line with the "script name", "status" and "status code":
1/19/2011 12:07:04 unikixvsam4 :KIX0501I Executing /pinv/invest1/io07210std/src/BBCONVRT.gnt
01/19/2011 12:07:04 unikixvsam4 :KIX0503I Terminating /pinv/invest1/io07210std/src/BBCONVRT.gnt
01/19/2011 12:07:04 unikixtran4 :KIX0314I Batch job BMI_TA_pdpg.ks ended, status = 0
01/19/2011 12:07:03 unikixvsam4 :KIX0503I Terminating /pinv/invest1/io07210std/src/ARPCR1.gnt
01/19/2011 12:07:04 unikixvsam4 :KIX0301I Entering (VER. 8.1.0p8 - 11/13/2007 )
01/19/2011 12:07:04 unikixvsam4 :KIX1001I Connected to database MQSeries
01/19/2011 12:07:04 unikixvsam4 :KIX0501I Executing /pinv/invest1/io07210std/src/BBCONVRT.gnt

Any help will be appreciated...

Thank You
Henk

Something to start:

#!/usr/bin/ksh

tail -f ${1}|awk  '/'"${2}"'.*ended/{'"exit "'$NF}'

Usage:

#viewlog logfile scriptName

Hi,

Thank you for the reply, but using the tail command, the script does not exit, although the status is already received within the active log file...

I tried using the more command, but because more only take the line that is there at that specific point in time, it also does not work...

Henk

awk does not print, because tail -f does not terminate, so awk clings to its buffers. Unfortunately, buffer control is not standard in awk. When using gawk, you can use fflush("") after a print command, in mawk you can use mawk -W interactive

1 Like