Created
January 16, 2015 21:58
-
-
Save theepicsnail/7931333f153c96721477 to your computer and use it in GitHub Desktop.
Monitor files, rerun script when they are modified
This file contains hidden or 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 | |
# find -- | |
split="-1" | |
for (( i = 0; i < ${#@}; i++ )); do | |
if [ "${!i}" == "--" ] | |
then | |
split=$i | |
i=${#@} | |
fi | |
done | |
if [ "$split" == "-1" ] | |
then | |
echo "Missing --" | |
echo "Expected $0 files ... -- command..." | |
exit 1 | |
fi | |
FILES=${@:1:$split-1} | |
shift $split | |
function quit () { | |
end | |
exit 0 | |
} | |
trap quit SIGINT | |
PID=0 | |
function end() { | |
if [ $PID -ne 0 ] | |
then | |
kill $PID 2>&1 >/dev/null | |
echo "Killed $PID" | |
fi | |
} | |
function begin() { | |
$* & | |
echo "Started $*" | |
PID=$! | |
} | |
begin $* | |
while true | |
do | |
inotifywait -q -e MODIFY ${FILES[@]} | |
end | |
begin $* | |
sleep 5 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment