Created
February 10, 2014 17:18
-
-
Save mrThe/8920239 to your computer and use it in GitHub Desktop.
Shell file changing monitor
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
# from: http://stackoverflow.com/questions/2972765/linux-script-that-monitors-file-changes-within-folders-like-autospec-does | |
#!/bin/bash | |
sha=0 | |
previous_sha=0 | |
update_sha() | |
{ | |
sha=`ls -lR . | sha1sum` | |
} | |
build () { | |
echo | |
echo "--> Monitor: Monitoring filesystem... (Press enter to force a build/update)" | |
} | |
changed () { | |
echo "--> Monitor: Files changed, Building..." | |
build | |
previous_sha=$sha | |
} | |
compare () { | |
update_sha | |
if [[ $sha != $previous_sha ]] ; then changed; fi | |
} | |
run () { | |
while true; do | |
compare | |
read -s -t 1 && ( | |
echo "--> Monitor: Forced Update..." | |
build | |
) | |
done | |
} | |
echo "--> Monitor: Init..." | |
echo "--> Monitor: Monitoring filesystem... (Press enter to force a build/update)" | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment