Created
June 9, 2010 05:36
-
-
Save Artanis/431100 to your computer and use it in GitHub Desktop.
Watches a file for changes and executes a command every time it does.
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/bash | |
# Watches a file for changes and executes a command every time it does. | |
# Need to enclose COMMAND in quotes, script dumbly calls $2. | |
# | |
# USE: | |
# exec-changes FILENAME COMMAND | |
LAST=`stat -c '%Y' $1` | |
while true; do | |
CURRENT=`stat -c '%Y' $1` | |
if [ $LAST -ne $CURRENT ]; then | |
echo "`date`: file changed" | |
`$2` | |
LAST=$CURRENT | |
fi | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment