This question already has an answer here:
- How do I watch a file for changes? 21 answers
I would like to invoke my chrome
or firefox
browser when a file that I specify is modified. How could I "watch" that file to do something when it gets modified?
Programmatically it seems the steps are.. basically set a never ending interval every second or so and cache the initial modification date, then compare the date every second, when it changes invoke X.
Install inotify-tools and write a simple shell script to watch a file.
As noted, you can use pyinotify:
E.g.:
This is more efficient than polling. The kernel tells you when it does the operation, without you having to constantly ask.
The other option is to use a checksum. You can use a pattern similar to nose's nosy.py. I use the one from dingus to check my directory for modifications and run the test suite.
Apparently, watchdog works on both Linux & OSX that can be used to monitor for changes in a directory as well with great example documentation. It also works with python3.x in case you don't want to be forced to use python2.x
Use FAM to put a monitor on the file.
use a quick hash function, a cron job, and off you go!
Also, this looks relevant: http://en.wikipedia.org/wiki/Inotify