trap on input to a file

2007-12-25 10:53:00

Apologies for the resend - this time with original question at the

bottom by popular request.

Thanks to:

Thomas Knox

Craig McLean

Sanjiv K. Bhatia

Denise Naomi Ishikawa

Bruce R. Zimmer

Ravi Channavajhala

for their answers. Ideas included using fstat() in C to continually

check the file, sending output to stderr (no can do - it's built

into the binary and I'd still need to set a constant watch),

modifying the program that's generating the message (no can do -

don't have access to them). But the winners, for us scripting guys,

are:

swatch, which is freely available and already set up to do this

stuff, and changing the output file to a named pipe (mknod <file> p).

Using the named pipe is the method I've gone for, mostly because I

received that response first (it also saves me time learning how to

configure swatch - another bonus). I can now read from that pipe and

act on the input as it is received.

One possible problem with this approach though, as highlighted by

Bruce Zimmer - if the pipe fills up, the application writing to it

may hang.

Original question:

I'm trying to get something set up to react to a specific message

which goes to a logfile, and could do with some advice on the best

way to do this.

There are a number of programs which append messages onto one file.

I'd like to run a command when one of those messages occurs. Thing

is, I want to run it *instantly*, and tail -f works in 1 second

intervals. I originally thought I could create a shell script with

the same name as the file, then figured out that was silly, since

all that'll happen is messages will be appended to the logfile.

I'm fairly decent at shell scripting, but don't know C or Perl,

which may help me do what I'm trying here.

If anyone has any suggestions, I'd appreciate them.

TIA,

Stuart Whitby.

S

U BEFORE POSTING please READ the FAQ located at

N ftp://ftp.cs.toronto.edu/pub/jdd/sun-managers/faq

. and the list POLICY statement located at

M ftp://ftp.cs.toronto.edu/pub/jdd/sun-managers/policy

A To submit questions/summaries to this list send your email message to:

N sun-managers@ececs.uc.edu

A To unsubscribe from this list please send an email message to:

G majordomo@codeprof.ececs.uc.edu

E and in the BODY type:

R unsubscribe sun-managers

S Or

. unsubscribe sun-managers original@subscription.address

L To view an archive of this list please visit:

I http://www.latech.edu/sunman.html

S

T

Comments

Got something to say?

You must be logged in to post a comment.