diff --git a/onfilechange.sh b/onfilechange.sh index 56cddeff7eb1293f382f912cf3298ec1f76d5c7d..e6d60fbbf18eddf5243234f6c64d555303d3eb03 100755 --- a/onfilechange.sh +++ b/onfilechange.sh @@ -14,6 +14,7 @@ # check a file change. # # licence: GNU GPL 3.0 +# source: https://git-repo.iml.unibe.ch/open-source/onfilechange # # ---------------------------------------------------------------------- # 2019-10-14 v1.0 <axel.hahn@iml.unibe.ch> first basic version @@ -30,7 +31,7 @@ sWatchFile= sMode= # ---- below are some internal variables -sVersion=1.0 +sVersion=1.01 # ---------------------------------------------------------------------- @@ -80,7 +81,7 @@ ENDOFHELP # param string text message to show function wd(){ if [ $bDebug -ne 0 ]; then - echo "[`date`] DEBUG " $* + echo "[`date`] DEBUG |" $* fi } @@ -128,10 +129,11 @@ function compareFilestatus(){ wd "Change detected." execCommand if [ $? -eq 0 ]; then - echo Command was successfuil. + echo Command was successful. echo wd "Re-Init File status" - initFilestatus + # initFilestatus + mv ${sTmpFile2} ${sTmpFile} else echo FAILED. fi @@ -153,11 +155,11 @@ function execCommand(){ # ---------------------------------------------------------------------- cat <<ENDOFHEAD -____________________________________________________________________________________ +______________________________________________________________________________ T R I G G E R C O M M A N D O N A F I L E C H A N G E -____________________________________________________________________________________ - v${sVersion} +______________________________________________________________________________ + v${sVersion} ENDOFHEAD @@ -183,11 +185,11 @@ fi while getopts ":c: :v :f: :h :i :s :w:" opt do - case $opt in - \?|h) - showHelp - exit 0 - ;; + case $opt in + \?|h) + showHelp + exit 0 + ;; v) bDebug=1 wd "debug is now ${bDebug}" @@ -208,14 +210,14 @@ do sMode=stats wd "forcing mode with stats command" ;; - w) - typeset -i iSleep=$OPTARG - wd "sleep $iSleep sec" - ;; - :) - echo "ERROR: Option -$opt requires an argument." >&2 - showHelp - exit 1 + w) + typeset -i iSleep=$OPTARG + wd "sleep $iSleep sec" + ;; + :) + echo "ERROR: Option -$opt requires an argument." >&2 + showHelp + exit 1 esac done @@ -250,11 +252,13 @@ if [ -z "${sCommand}" ]; then echo ERROR: set a ${sCommand} with param -s exit 1 fi +echo # ---------------------------------------------------------------------- # GO # ---------------------------------------------------------------------- +echo ">>>>> start" myset=`echo ${sWatchFile} | sha1sum | cut -f 1 -d " "` sTmpFile="/tmp/`basename $0`-${myset}-last.tmp" sTmpFile2="/tmp/`basename $0`-${myset}-current.tmp" @@ -266,15 +270,17 @@ case $sMode in if [ $? -eq 0 ]; then inotifywait -e attrib -e modify ${sWatchFile} && execCommand else + echo "ERROR: inotifywait only can notify if all watched files exist." + echo "Use parameter -s to use stats for file detection, This mode also allows that a file is deleted." wd sleep ${iSleep} sleep ${iSleep} - echo "WARNING: inotifywait only can notify if all watched files exist. You can use -s to use stats for file detection" + exit 2 fi done ;; "stats") - wd "--- init" + wd "--- initial read of watched files" initFilestatus echo waiting for file changes ...