BASH, autorun script on directory update?

Go To StackoverFlow.com

4

Is there any way of setting up a simple bash script such as

chmod a+xr -R ~/lib/

but in a way such that this script is run automatically when any file is created or moved to inside the lib directory, and directories nested within lib?

Sort of like waiting for some event to happen, triggering execution of the script - that's the information I'm looking for.

2012-04-04 04:32
by NoName
For this specific case you might want to look into <code>umask</code> - l0b0 2012-04-04 07:33


4

Yes, . . .

. . . major Unix versions have event framework extensions to the traditional Posix core services.

If you are taking about Linux, see dnotify and the later facility, inotify.

These facilities don't really have much to do with bash, but dnotify is oriented to run scripts. These features are probably already in your kernel, but you most likely will need to install a package such as inotify-tools in order to easily access them.

The BSD systems and other Unix-proper systems have equivalent mechanisms.

2012-04-04 04:41
by DigitalRoss
inotify does seem to do half of the job - watching for when the directory is updated, thanks for linking that. Now I just need to figure out some way of making the bash program run when inotify detects the event.. That seems difficult however, since I'll probably be running inotify with C, how would I get it to do something in bash (unless C has some module which can chmod?)? Thumbs up but it's still not entirely answere - NoName 2012-04-04 04:51
But while looking further into inotify, I find out that they do indeed have a bash module for it, which means I don't need to use C and can do it all from BASH - I should be good from here, thanks for leading me to the answer - NoName 2012-04-04 04:56
Ads