[lug] How to monitor directory changes from a shell?
Phil Rasch
pjr at ucar.edu
Thu Feb 22 19:45:27 MST 2007
I need to employ a simple mechanism from within a shell script that
will notify the script when a directory changes status. Ideally the
script would call a utility that will "pause" until the directory has
something written to it. When the directory changes, the utility would
react by quitting, and return control to the script.
I know that I can do this by simply embedding a sleep and a stat
command inside a loop in the shell script, but is there any more
elegant (yet easy) way to do this under linux? I want the script to
respond to changes within a few seconds or faster. It seems wrong
to use the sleep/stat/loop method.
I dont mind using perl, python, or any particular shell to help me in
this, but I cant think of any easy way to go.
I suppose I can write some C code that employs a call to "select" or "poll",
but rather than polish up my rusty C programming skills I thought I would
ask here first. Maybe one of you has already written the code?
Thanks for your advice!
Phil
More information about the LUG
mailing list