Skip to content

Instantly share code, notes, and snippets.

@ysugimoto
Created October 9, 2012 10:38
Show Gist options
  • Save ysugimoto/3857887 to your computer and use it in GitHub Desktop.
Save ysugimoto/3857887 to your computer and use it in GitHub Desktop.
inotifywait file watching handler
#!/bin/sh
# kill already process
PROC=`pgrep -f inotifywait`
if [ -n "${PROC}" ]; then
echo $PROC | xargs kill
fi
/usr/bin/inotifywait -e create,modify -mrq /home/my.file | while read line; do
path=`echo $line | /bin/awk '{print $1$3}'`
echo $path | some program
done & # daemon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment