[lug] How to monitor directory changes from a shell?

D. Stimits stimits at comcast.net
Thu Feb 22 20:40:02 MST 2007


Phil Rasch wrote:

>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.
>  
>
There is an asyncronous I/O (AIO) extension which might do what you 
want. I have future plans for this myself, but haven't tested it yet. 
You might look at this:
http://lwn.net/Articles/190738/

D. Stimits, stimits AT comcast DOT net



More information about the LUG mailing list