Skip to content
Snippets Groups Projects
Commit 7c42e3c4 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

v1.01

- added comments
- inotify mode exits if a watchfile is away
parent f81c72c2
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# check a file change. # check a file change.
# #
# licence: GNU GPL 3.0 # 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 # 2019-10-14 v1.0 <axel.hahn@iml.unibe.ch> first basic version
...@@ -30,7 +31,7 @@ sWatchFile= ...@@ -30,7 +31,7 @@ sWatchFile=
sMode= sMode=
# ---- below are some internal variables # ---- below are some internal variables
sVersion=1.0 sVersion=1.01
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
...@@ -80,7 +81,7 @@ ENDOFHELP ...@@ -80,7 +81,7 @@ ENDOFHELP
# param string text message to show # param string text message to show
function wd(){ function wd(){
if [ $bDebug -ne 0 ]; then if [ $bDebug -ne 0 ]; then
echo "[`date`] DEBUG " $* echo "[`date`] DEBUG |" $*
fi fi
} }
...@@ -128,10 +129,11 @@ function compareFilestatus(){ ...@@ -128,10 +129,11 @@ function compareFilestatus(){
wd "Change detected." wd "Change detected."
execCommand execCommand
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo Command was successfuil. echo Command was successful.
echo echo
wd "Re-Init File status" wd "Re-Init File status"
initFilestatus # initFilestatus
mv ${sTmpFile2} ${sTmpFile}
else else
echo FAILED. echo FAILED.
fi fi
...@@ -153,10 +155,10 @@ function execCommand(){ ...@@ -153,10 +155,10 @@ function execCommand(){
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
cat <<ENDOFHEAD 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 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 ENDOFHEAD
...@@ -250,11 +252,13 @@ if [ -z "${sCommand}" ]; then ...@@ -250,11 +252,13 @@ if [ -z "${sCommand}" ]; then
echo ERROR: set a ${sCommand} with param -s echo ERROR: set a ${sCommand} with param -s
exit 1 exit 1
fi fi
echo
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# GO # GO
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
echo ">>>>> start"
myset=`echo ${sWatchFile} | sha1sum | cut -f 1 -d " "` myset=`echo ${sWatchFile} | sha1sum | cut -f 1 -d " "`
sTmpFile="/tmp/`basename $0`-${myset}-last.tmp" sTmpFile="/tmp/`basename $0`-${myset}-last.tmp"
sTmpFile2="/tmp/`basename $0`-${myset}-current.tmp" sTmpFile2="/tmp/`basename $0`-${myset}-current.tmp"
...@@ -266,15 +270,17 @@ case $sMode in ...@@ -266,15 +270,17 @@ case $sMode in
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
inotifywait -e attrib -e modify ${sWatchFile} && execCommand inotifywait -e attrib -e modify ${sWatchFile} && execCommand
else 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} wd sleep ${iSleep}
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 fi
done done
;; ;;
"stats") "stats")
wd "--- init" wd "--- initial read of watched files"
initFilestatus initFilestatus
echo waiting for file changes ... echo waiting for file changes ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment