Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
onfilechange
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
onfilechange
Commits
7c42e3c4
Commit
7c42e3c4
authored
5 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
v1.01
- added comments - inotify mode exits if a watchfile is away
parent
f81c72c2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
onfilechange.sh
+28
-22
28 additions, 22 deletions
onfilechange.sh
with
28 additions
and
22 deletions
onfilechange.sh
+
28
−
22
View file @
7c42e3c4
...
...
@@ -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.0
1
# ----------------------------------------------------------------------
...
...
@@ -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 successfu
i
l.
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
}
e
cho
"WARNING: inotifywait only can notify if all watched files exist. You can use -s to use stats for file detection"
e
xit
2
fi
done
;;
"stats"
)
wd
"--- init"
wd
"--- init
ial read of watched files
"
initFilestatus
echo
waiting
for
file changes ...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment