Skip to content

Instantly share code, notes, and snippets.

@Artanis
Created June 9, 2010 05:36
Show Gist options
  • Save Artanis/431100 to your computer and use it in GitHub Desktop.
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.
#! /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