Monitor Directory for Changes
Here’s a simple script that I setup for my development WSGI server to reload itself once changes in source code are detected:
#!/bin/bash while true; do A=`find $1 -printf '%t' | md5sum`; sleep 1 B=`find $1 -printf '%t' | md5sum`; if [ "$A" != "$B" ]; then echo "Detected change, doing: $2" eval $2 fi done
It’s very simple (a poor-man’s replacement for inotify) and doesn’t do anything complicated. Usage ./monitor.sh application "my-reload-services.sh"
. You can filter out unwanted stuff like maybe *.swp files by referring to the man find
pages.
What do you use to monitor for changes? How can the above script be improved?
i would be interested, if there’s something similar available for windows:D
wasn’t able to find something, to start a program, once the php & html files in the configured directory where changed
You could try cygwin. Or code it up in PHP or Python instead, an endless monitor loop that executes a program once changes have been detected. It’s fairly simple. You could try PowerShell if you feel adventurous.
You can find & sum all those files only once a second, instead of twice. Compute A before the loop and then set A to B when a change happens.
Excellent tip, thank you, Ondra.
i think it’s better to use Linux API for that – inotify.
And in repo you can find “iwatch” tool.
In debian based – apt-get install iwatch
Really awesome tool and very simple for use.
Agreed, although there’s a thinner wrapper around libinotify called `inotify-tools` which is really sweet. Also, I was initially looking for something that needs no wrappers, utilities beyond what’s already generally available.