#!/usr/bin/env bash

#UTILPATH=`echo "$0" | sed 's/\/[^\/]+$//'`
UTILPATH=${0%/*}

FILENAME=$1
STARTSCRIPT=$2
STOPSCRIPT=$3

touch "$FILENAME"

(
while [ -e "$FILENAME" ] ; do
  sleep 1
  inotifywait -e ATTRIB -t 10 "$FILENAME" > /dev/null 2&>/dev/null
done

$STOPSCRIPT

kill `cat /tmp/pidwrapper`
) &

$UTILPATH/runwrapper.sh "$STARTSCRIPT" 
