The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
the shell not pause when execute read command neruppu Shell Programming and Scripting 14 07-06-2008 07:34 PM
pause needed for corn shell dennysavard UNIX for Dummies Questions & Answers 7 12-09-2007 02:16 PM
pause? where art thou? 01000101 High Level Programming 3 05-15-2006 07:42 PM
how to pause another process? daneensign UNIX for Dummies Questions & Answers 1 02-14-2006 12:27 AM
system("PAUSE") Problem..... mbolthouse High Level Programming 2 10-03-2001 01:21 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-20-2008
gxdanh gxdanh is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
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 (permalink)  
Old 10-21-2008
majormark majormark is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 35
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 (permalink)  
Old 10-21-2008
gxdanh gxdanh is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
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 (permalink)  
Old 10-24-2008
gxdanh gxdanh is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 3
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.

when I tried the command below,

getline i < "/dev/tty"

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

Please help.
Thanks
George
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0