Created
January 25, 2012 17:30
-
-
Save benlumley/1677459 to your computer and use it in GitHub Desktop.
Run a command, and then watch a folder and re-run whenever folder contents change - kind of poor mans inotify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Usage: ./folderwatch.sh /folder/to/watch cmdtorun | |
# | |
check() { | |
dir="$1" | |
cmd="$2"; | |
chsum1=`find $dir -type f -exec md5sum {} + | md5sum | awk '{print $1}'` | |
chsum2=$chsum1 | |
while [ "$chsum1" = "$chsum2" ] | |
do | |
sleep 10 | |
chsum2=`find $dir -type f -exec md5sum {} + | md5sum | awk '{print $1}'` | |
done | |
$cmd | |
check "$@" | |
} | |
$2 | |
check "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment