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
f81c72c2
Commit
f81c72c2
authored
5 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add readme
parent
d2de5025
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+73
-0
73 additions, 0 deletions
README.md
onfilechange.sh
+0
-0
0 additions, 0 deletions
onfilechange.sh
with
73 additions
and
0 deletions
README.md
+
73
−
0
View file @
f81c72c2
# onfilechange
# onfilechange
A Shell script that watches a given file or multiple files.
If one of the watched file changes then a given command will be exxecuted.
It loops permanently; you need to stop it by Ctrl + C and/ or can
use it as systemd watcher daemon.
It uses stats for wide compatibility but prefers inotifywatch to
check a file change.
licence: Free software GNU GPL 3.0
Source: https://git-repo.iml.unibe.ch/open-source/onfilechange
## Installation
*
Copy the bash script somewhere you like.
*
set execute permissions
`chmod 0755 onfilechange.sh`
## Usage
```
Parameters
-c [command]
command to execute on a file change
-f [filename(s)]
filenames to watch; separate multiple files with space and put all in quotes
-h
show this help
-i
force inotifywait command
-s
force stats command
-v
verbose mode; enable showing debug output
-w [integer]
for stats mode: wait time in seconds betweeen each test or on missing file; default: 5 sec
```
## Test on command line
To make a test on commandline touch a testfile
`touch /tmp/mytestfile`
.
The start the script with enabled debugging (-d) in a 2nd terminal:
`/usr/local/bin/onfilechange.sh -v -f "/tmp/mytestfile" -c 'echo "hello"'`
Each time you touch the testfile it should show "hello".
## Use as systemd service
In
`/etc/systemd/system/`
create a service config file
**onfilechange-demo.service**
```
[Unit]
Description=Onfilechange edemo
Wants=multi-user.target
[Service]
ExecStart=/usr/local/bin/onfilechange.sh -f "/tmp/mytestfile" -c 'systemctl restart apache2'
Restart=on-failure
RestartSec=5s
SyslogIdentifier=onfilechange
User=root
Group=root
Type=simple
[Install]
WantedBy=multi-user.target
```
Check if the service exists
`systemctl status onfilechange-demo`
. If so you can start and stop it with
`systemctl [start|stop] onfilechange-demo`
This diff is collapsed.
Click to expand it.
onfilechange.sh
100644 → 100755
+
0
−
0
View file @
f81c72c2
File mode changed from 100644 to 100755
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