Execute script/program when file changes
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:
- inchron:
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:
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':
inoticoming - trigger actions when files hit an incoming directory
there was an answer to a similar question on askubuntu:
https://askubuntu.com/a/43848/1223
Another quick and dirty way to do this is to use inotifywait
from the inotify-tools package (on fedora).
I like this method better because you can do it all from a single bash command line. I often use this when I'm writing small programs to see the results of what I just saved.
while [[ 1 ]]; do inotifywait -e modify <filename>; make && ./helloworld; done