#!/bin/sh WATCH_FULL_FILE="$1" shift 1; if ! [ -e "$WATCH_FULL_FILE" ]; then echo "No such file or directory $WATCH_FULL_FILE"; fi; WATCH_DIR=`dirname "$WATCH_FULL_FILE"` WATCH_FILE=`basename "$WATCH_FULL_FILE"` if which inotifywait > /dev/null 2>&1; then inotifywait -m -e close_write,moved_to,create $WATCH_DIR | while read -r directory events filename; do if [ "x$filename" = "x$WATCH_FILE" ]; then ( exec "$@" ); fi; done; else CURR_TIME=$(stat -c '%Y' "$WATCH_FULL_FILE"); while sleep 1; do NEW_TIME=$(stat -c '%Y' "$WATCH_FULL_FILE"); if [ "x$NEW_TIME" != "x$CURR_TIME" ]; then CURR_TIME=$NEW_TIME ( exec "$@" ); fi; done; fi;