Skip to content

Instantly share code, notes, and snippets.

@benlumley
Created January 25, 2012 17:30
Show Gist options
  • Save benlumley/1677459 to your computer and use it in GitHub Desktop.
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
#!/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