Skip to content

Instantly share code, notes, and snippets.

@perpen
Created February 27, 2019 14:21
Show Gist options
  • Save perpen/7bfa4445f3aab9348da2f4bf4f5b185e to your computer and use it in GitHub Desktop.
Save perpen/7bfa4445f3aab9348da2f4bf4f5b185e to your computer and use it in GitHub Desktop.
inw2 - inotifywait and restart
#!/bin/bash
inot_args="-qq -e modify @.git"
for arg in "$@"; do
case $arg in
--) break ;;
*) inot_args+=" $arg"; shift ;;
esac
done
shift
#echo inot_args: $inot_args
#echo rest: $*
arg0=$(basename $0)
[ -z $1 ] && {
echo "Usage: $arg0 <inotifywait opt> ... -- <cmd> <arg> ..." 1>&2
exit 2
}
while :; do
echo "# Files modified"
"$@" &
echo "##################################### Done"
inotifywait $inot_args || exit 1
pkill -f "^$*\$"
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment