[KLUG Members] Executing a root program when a file changes

Adam Tauno Williams members@kalamazoolinux.org
Fri, 26 Oct 2001 09:41:06 -0400 (EDT)


>I am writing a root shell script to maintain a log file.  My preference
>is to be able to execute this script when the log file changes, but no
>more than once a day.  I don't want to start a daemon to watch for this
>event. Is there a command (like "logger"??) or tool that I can use to
>catch or wait for this changed state and execute the root program?

There are is one of "easy" ways to do this.

A.  Send the message with logger,  so it goes into syslog

B.  Via /etc/syslog.conf either deliver the message via e-mail to a program. 
The program will be started via smrsh by your MDA,  only when a message
arrives.  A handy way to build triggers.  You have to be careful about security.

There are also lots of log monitors that can watch for patterns and perform a
variety of operations.  This may be/seem overkill but these always come in handy
later for lots of things.

In general I'd remind you that log files are for logging,  not IPC.  Using log
files for IPC is a tricky business and will eventually get you into trouble. 
Perl supports SysV IPC if you need to script the movement of data between
applications (so does PHP).

Another trigger mechanism is to use xinetd to listen on a socket and spawn you
program when a connection comes in.  You probably have xinetd running anyway, 
and you can make it only accept connections from the local machine (which beats
using the e-mail trigger).  But then your client has to send a message to the
correct socket and you thus involve NSS (name resolution, /etc/services, etc...)

Utilities like netpipes, ncat, etc... allow you to "sort of" use socket
communication from shell scripts.  Both Perl and PHP support socket level
communication natively.

Systems and Network Administrator
Morrison Industries
1825 Monroe Ave NW
Grand Rapids, MI. 49505