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
b4a936dc
Commit
b4a936dc
authored
5 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
use stat as default
parent
d60dc056
No related branches found
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
-25
28 additions, 25 deletions
onfilechange.sh
with
28 additions
and
25 deletions
onfilechange.sh
+
28
−
25
View file @
b4a936dc
...
@@ -10,14 +10,15 @@
...
@@ -10,14 +10,15 @@
# It loops permanently; you need to stop it by Ctrl + C and/ or can
# It loops permanently; you need to stop it by Ctrl + C and/ or can
# use it as systemd watcher daemon.
# use it as systemd watcher daemon.
#
#
# It uses stat
s
for wide compatibility but
prefers
inotifywatch to
# It uses stat for wide compatibility but
can enable
inotifywatch to
# check a file change.
# check a file change
by an event
.
#
#
# licence: GNU GPL 3.0
# licence: GNU GPL 3.0
# source: https://git-repo.iml.unibe.ch/iml-open-source/onfilechange
# source: https://git-repo.iml.unibe.ch/iml-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
# 2019-10-21 v1.03 <axel.hahn@iml.unibe.ch> use stat as default
# ======================================================================
# ======================================================================
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
...
@@ -31,7 +32,7 @@ sWatchFile=
...
@@ -31,7 +32,7 @@ sWatchFile=
sMode
=
sMode
=
# ---- below are some internal variables
# ---- below are some internal variables
sVersion
=
1.0
2
sVersion
=
1.0
3
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
...
@@ -55,11 +56,11 @@ PRAMETERS:
...
@@ -55,11 +56,11 @@ PRAMETERS:
-i
-i
force inotifywait command
force inotifywait command
-s
-s
force stat
s
command
force stat command
(default mode)
-v
-v
verbose mode; enable showing debug output
verbose mode; enable showing debug output
-w [integer]
-w [integer]
for stat
s
mode: wait time in seconds betweeen each test or on missing file; default: 5 sec
for stat mode: wait time in seconds betweeen each test or on missing file; default: 5 sec
EXAMPLES:
EXAMPLES:
`basename
$0
` -f /home/me/touchfile.txt -c "ls -l"
`basename
$0
` -f /home/me/touchfile.txt -c "ls -l"
...
@@ -68,8 +69,8 @@ EXAMPLES:
...
@@ -68,8 +69,8 @@ EXAMPLES:
`basename
$0
` -f "/home/me/touchfile.txt home/me/touchfile2.txt" -c "ls -l"
`basename
$0
` -f "/home/me/touchfile.txt home/me/touchfile2.txt" -c "ls -l"
watch touchfile.txt and touchfile2.txt
watch touchfile.txt and touchfile2.txt
`basename
$0
` -f /home/me/touchfile.txt -s -w 10 -c "
ls -l
"
`basename
$0
` -f /home/me/touchfile.txt -s -w 10 -c "
echo hello
"
watch touchfile.txt every 10 sec with stat
s
and
make a file listing
on change
watch touchfile.txt every 10 sec with stat and
show "hello"
on
a
change
ENDOFHELP
ENDOFHELP
...
@@ -94,7 +95,7 @@ function listFiles(){
...
@@ -94,7 +95,7 @@ function listFiles(){
ls
-ld
${
sWatchFile
}
2>&1
ls
-ld
${
sWatchFile
}
2>&1
}
}
# for stat
s
: helper to get current file status
# for stat: helper to get current file status
#
#
# global (string) $sWatchFile
# global (string) $sWatchFile
function
getFilestatus
(){
function
getFilestatus
(){
...
@@ -104,7 +105,7 @@ function getFilestatus(){
...
@@ -104,7 +105,7 @@ function getFilestatus(){
done
done
}
}
# for stat
s
: inititalize file change detection
# for stat: inititalize file change detection
#
#
# global (string) $TmpFile last/ initial file status
# global (string) $TmpFile last/ initial file status
# global (string) $sTmpFile2 current file status
# global (string) $sTmpFile2 current file status
...
@@ -114,7 +115,7 @@ function initFilestatus(){
...
@@ -114,7 +115,7 @@ function initFilestatus(){
cp
-p
${
sTmpFile
}
${
sTmpFile2
}
cp
-p
${
sTmpFile
}
${
sTmpFile2
}
}
}
# for stat
s
: compare file status and execute command on change
# for stat: compare file status and execute command on change
#
#
# global (string) $TmpFile last/ initial file status
# global (string) $TmpFile last/ initial file status
# global (string) $sTmpFile2 current file status
# global (string) $sTmpFile2 current file status
...
@@ -163,19 +164,19 @@ ______________________________________________________________________________
...
@@ -163,19 +164,19 @@ ______________________________________________________________________________
ENDOFHEAD
ENDOFHEAD
which
inotifywai
t
>
/dev/null 2>&1
which
sta
t
>
/dev/null 2>&1
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
ERROR: the
command
inotify
was not found on your system
,
echo
ERROR: the
command
stat
was not found on your system
.
which
sta
t
>
/dev/null 2>&1
which
inotifywai
t
>
/dev/null 2>&1
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
ERROR: the
command
sta
t
was not found on your system
,
echo
ERROR: the
command
inotifywai
t was not found on your system
.
exit
2
exit
2
fi
fi
echo
"INFO: enabling compatibility mode with stats command"
echo
"INFO: enabling inotifywait command"
sMode
=
stats
else
echo
"INFO: inotifywait command detected"
sMode
=
inotifywait
sMode
=
inotifywait
else
echo
"INFO: stat command detected"
sMode
=
stat
fi
fi
if
[
$#
-eq
0
]
;
then
if
[
$#
-eq
0
]
;
then
...
@@ -207,8 +208,8 @@ do
...
@@ -207,8 +208,8 @@ do
wd
"forcing mode with inotifywait command"
wd
"forcing mode with inotifywait command"
;;
;;
s
)
s
)
sMode
=
stat
s
sMode
=
stat
wd
"forcing mode with stat
s
command"
wd
"forcing mode with stat command"
;;
;;
w
)
w
)
typeset
-i
iSleep
=
$OPTARG
typeset
-i
iSleep
=
$OPTARG
...
@@ -222,10 +223,12 @@ do
...
@@ -222,10 +223,12 @@ do
done
done
cat
<<
ENDOFINFO
cat
<<
ENDOFINFO
--- summary
checking file [
${
sWatchFile
}
]
checking file [
${
sWatchFile
}
]
with command [
${
sMode
}
]
with command [
${
sMode
}
]
with a sleep time of
[
${
iSleep
}
] seconds
with a sleep time of [
${
iSleep
}
] seconds
and on change start command [
${
sCommand
}
]
and on change
I
start
the
command [
${
sCommand
}
]
...............................................................................
...............................................................................
...
@@ -271,7 +274,7 @@ case $sMode in
...
@@ -271,7 +274,7 @@ case $sMode in
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
"ERROR: inotifywait only can notify if all watched files exist."
echo
"Use parameter -s to use stat
s
for file detection, This mode also allows that a file is deleted."
echo
"Use parameter -s to use stat for file detection, This mode also allows that a file is deleted."
wd
sleep
${
iSleep
}
wd
sleep
${
iSleep
}
sleep
${
iSleep
}
sleep
${
iSleep
}
exit
2
exit
2
...
@@ -279,7 +282,7 @@ case $sMode in
...
@@ -279,7 +282,7 @@ case $sMode in
done
done
;;
;;
"stat
s
"
)
"stat"
)
wd
"--- initial read of watched files"
wd
"--- initial 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