Is there a way to set something like a trigger on a file, so that everytime the file is changed a script or program will be executed?

I only found a mechanism for this within a shell script but would like to know if there is a mechanism for that on operating system basis (so that I don't have to manually run a background program). A solution on operating system basis would be a cron-job that runs every few seconds, but this does not look like an adequate solution to me.

It is for Debian, btw.

Thanks for help.

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

one of your options is the inotify subsystem of the linux kernel:

inotify is a Linux kernel subsystem that acts to extend filesystems to notice changes to the filesystem, and report those changes to applications

but since inotify is kernel-land, you need something in user-space to actually use it:

The inotify cron daemon (incrond) is a daemon which monitors filesystem events and executes commands defined in system and user tables. It's use is generally similar to cron(8).

Gamin is a monitoring system for files and directories that independently implements a subset of FAM, the File Alteration Monitor. Running as a service, it allows for the detection of modifications to a file or directory. gam_server functions as a daemon for Gamin.

inoticoming - trigger actions when files hit an incoming directory

there was an answer to a similar question on askubuntu:

http://askubuntu.com/a/43848/1223

link|improve this answer
1  
Just to let you know: I now use inotify in combination with incron, which works perfectly fine for me. I'm aware that incron is still in alpha phase but it does a really well job. Thank you very much for this great advise! – cyphorious Dec 2 '11 at 13:10
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.