Created
January 31, 2019 17:43
-
-
Save ixaxaar/f6a421ec5a5fab35c770d10f844f526e to your computer and use it in GitHub Desktop.
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/sh | |
############################################################################################### | |
# Run as ./run_on_save.sh ./file/to/watch ./script/to/run.sh --args --to --give --to --script | |
############################################################################################### | |
# get the current path | |
CURPATH=`pwd` | |
TO_WATCH=$1 | |
shift | |
TO_EXEC=$1 | |
shift | |
inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \ | |
-e close_write $TO_WATCH | while read date time dir file; do | |
FILECHANGE=${dir}${file} | |
# convert absolute path to relative | |
FILECHANGEREL=`echo "$FILECHANGE" | sed 's_'$CURPATH'/__'` | |
bash $TO_EXEC $1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment