Pause for response from the log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pause for response from the log file
# 1  
Old 10-20-2008
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
# 2  
Old 10-21-2008
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.
# 3  
Old 10-21-2008
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.
# 4  
Old 10-24-2008
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.Smilie

when I tried the command below,

getline i < "/dev/tty"

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

Please help.
Thanks
George
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pause before exit

6) printf "\n GoodBye! \n\n"; exit ;; I am trying modify the above command to pause a couple of seconds before exiting, so a message can be displayed. Thank you :). (8 Replies)
Discussion started by: cmccabe
8 Replies

2. Shell Programming and Scripting

[Solved] Need Help in reading Response file

Hi All, I have a requirement to read response file which looks like below Ex: NAME=SAM DOB=01/01/1980 ADDRESS= 7658 James Street NewYork 0000 Now, I need to take NAME, DOB, ADDRESS into variables I am fine taking NAME and DOB I need help on how can I... (6 Replies)
Discussion started by: mallak
6 Replies

3. UNIX for Dummies Questions & Answers

Is it better/possible to pause the rsyncing of a very large directory?

Possibly a dumb question, but I'm deciding how I'm going to do this. I'm currently rsyncing a 25TB directory (with several layers of sub directories most of which have video files ranging from 500 megs to 4-5 gigs), from one NAS to another using rsync -av. By the time I need to act ~15TB should... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

4. Shell Programming and Scripting

Calculate response time from log

I have a running log file (jboss_server.log) which rotates at midnight . I need to constantly check and calculate the time for each thread and alert if it doesnt complete within 60 minute. For example my log file has following printed . I want to run a script in cron every 30 minutes and... (2 Replies)
Discussion started by: gubbu
2 Replies

5. Shell Programming and Scripting

How to pause a shell script

Hi, I've written a shell script to take photos with my camera. After every picture taken, the picture is transmitted to the computer via usb and then deleted on the camera. But sometimes there's an error and the picture is not deleted and so, after a certain time, the camera chip will be... (4 Replies)
Discussion started by: McLennon
4 Replies

6. AIX

How to pause a while loop while reading from a file

Hi, I am building a script to grep for a string in all the files from a folder and display the results. I am reading the files one by one by placing the names in other file using while loop my code is as below while read inp do chk=`grep -c "$str" $pth/$inp` ... (2 Replies)
Discussion started by: sekhar gajjala
2 Replies

7. UNIX for Dummies Questions & Answers

pause() problems

well is gets stuck and i dont know why....... pid=fork(); if(pid==0) { pause(); write(1,"child",5); exit(0); } else { sleep(1); kill(pid,SIGCONT); write(1,"parent",5); wait(0); } all=1; (1 Reply)
Discussion started by: IdleProc
1 Replies

8. Programming

pause? where art thou?

ok, im somewhat of an advanced programmer for the windows-side of C/C++, and the system command to pause the console is 'system("pause");'.... i just recently transfered over to Slackware 3.3 (yes, its old, but i <3 text), and pause is not the command for pausing the command line. is there any... (3 Replies)
Discussion started by: 01000101
3 Replies

9. UNIX for Dummies Questions & Answers

how to pause another process?

I guess I posted in wrong forum before. How do I pause another process and then restart it on linux? The other process doesn't listen for anything. Thanks for any help you can offer. Dane :confused: (1 Reply)
Discussion started by: daneensign
1 Replies
Login or Register to Ask a Question