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
GitLab 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
No related branches found
No related tags found
No related merge requests found
Changes
1
Show 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 @@
...
@@ -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.0
1
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
...
@@ -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 successfu
i
l.
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
}
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
fi
done
done
;;
;;
"stats"
)
"stats"
)
wd
"--- init"
wd
"--- init
ial read of watched files
"
initFilestatus
initFilestatus
echo
waiting
for
file changes ...
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