Pause for response from the log file

Hello,
I am writing a shell script to search an active log file. If an "error" or "aborted" found, echo an acknowledgment message and wait until the user presses ENTER key.

tail -f log.file |nawk '
{print $0}
$0 ~ /error/ {
print "Error found. Press ENTER to acknowledge."
getline i < "-"
}
$0 ~ /aborted/ {
print "Error found. Press ENTER to acknowledge."
getline i < "-"
}
'
Because this is an active log file, the messages keep coming to the log file all the time. The next incoming message, after error or aborted found, is read as response to the message.

I may have multiple Putty sessions running at same time. Only Putty session that displayed message can accept the response from user.

Thanks.
George

I think you can do an infinite loop with awk and at some interval check to see if the last line from the log file has a greater line number than the one you previously checked.

use the NR in awk.

Thank you MajorMark.

my purpose for this scripting is to provide exception processing notification and acknowledgement.

I want to pause the screen that is scrolling as the messages are coming to the log. The user may not catch the error while the screen is scrolling other informational messages. If an error is found, I would like to pause for a user response. Once the user presses ENTER, the screen resumes scrolling again.

With the code above it paused, but did not wait for a user response.

hello everyone,
I am able to go further with getline from exact terminal device.

From my UNIX prompt, my terminal device is /dev/pts/26.
$ > tty
/dev/pts/26
$ >

So, I changed the getline command as below:

tail -f log.file |nawk '
{print $0}
$0 ~ /error/ {
print "Error found. Press ENTER to acknowledge."
getline i < "/dev/pts/26"
}
$0 ~ /aborted/ {
print "Error found. Press ENTER to acknowledge."
getline i < "-"
}
'
It paused and wait for acknowledgement. But ...
How can I get current terminal device into my nawk? each time I log in, I will get diff. terminal device.

I tried the following but all fail:
=1= Begin stmt
BEGIN {dev = ENVIRON["$devID"]}
. . .
getline i < "$dev"

note: I export tty value prior nawk stmt (export devID=`tty`)

=2= and ...
getline i < system ("echo $devID")

getline i < system ("echo `tty`")

getline i < "ENVIRON["$devID"]"

None of them seem to work for me.:o

when I tried the command below,

getline i < "/dev/tty"

It works most of the time. :slight_smile: Once in a while, it failed too.

Please help.
Thanks
George