https://github.com/devilbox/watcherd
A shell daemon that will listen for directory changes and execute custom commands for each event.
https://github.com/devilbox/watcherd
inotify inotifywait watcher
Last synced: 17 days ago
JSON representation
A shell daemon that will listen for directory changes and execute custom commands for each event.
- Host: GitHub
- URL: https://github.com/devilbox/watcherd
- Owner: devilbox
- License: mit
- Created: 2017-09-16T13:25:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T21:53:17.000Z (over 2 years ago)
- Last Synced: 2025-05-12T23:41:56.608Z (17 days ago)
- Topics: inotify, inotifywait, watcher
- Language: Shell
- Homepage: http://devilbox.org
- Size: 77.1 KB
- Stars: 54
- Watchers: 4
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# watcherd

[](https://github.com/devilbox/watcherd/actions/workflows/linting.yml)
[](https://github.com/devilbox/watcherd/actions/workflows/test-linux.yml)
[](https://github.com/devilbox/watcherd/actions/workflows/test-macos.yml)
[](https://github.com/devilbox/watcherd/actions/workflows/test-windows.yml)
[](https://opensource.org/licenses/MIT)**[watcherd](https://github.com/devilbox/watcherd/blob/master/bin/watcherd)** will look for directory changes (added and deleted directories) under the specified path (`-p`) and will execute specified commands or shell scripts (`-a`, `-d`) depending on the event.
Once all events have happened during one round (`-i`), a trigger command can be executed (`-t`).
Note, the trigger command will only be execute when at least one add or delete command has succeeded with exit code 0.---
If you need the same functionality to monitor changes of listening ports, check out **[watcherp](https://github.com/devilbox/watcherp)**.
---
### Modes
**[watcherd](https://github.com/devilbox/watcherd/blob/master/bin/watcherd)** can either use the native [inotifywait](https://linux.die.net/man/1/inotifywait) implementation or if this is not available on your system use a custom bash implementation. The default is to use bash.
### Placeholders
There are two placeholders available that make it easier to use custom commands/scripts for the add (`-a`) or delete (`-d`) action.:
* `%p` Full path to the directory that was added or deletd
* `%n` Name of the directory that was added or deletedYou can specify the placeholders as many times as you want. See the following example section for usage.
### Examples
By using **[vhost-gen](https://github.com/devilbox/vhost-gen)** (which is capable of creating Nginx or Apache vhost config files for normal vhosts or reverse proxies), the following will be able to create new nginx vhosts on-the-fly, simply by adding or deleting folders in your main www directory. The trigger command will simply force nginx to reload its configuration after directory changes occured.
```shell
# %n will be replaced by watcherd with the new directory name
# %p will be replaced by watcherd with the new directory path
watcherd -v \
-p /shared/httpd \
-a "vhost-gen -p %p -n %n -s" \
-d "rm /etc/nginx/conf.d/%n.conf" \
-t "nginx -s reload"
```### Usage
```bash
Usage: watcherd -p -a -d [-t -w -i -v -c]
watcherd --help
watcherd --versionwatcherd will look for directory changes (added and deleted directories) under
the specified path (-p) and will execute specified commands or shell scripts
(-a, -d) depending on the event. Once all events have happened during one round
(-i), a trigger command can be executed (-t). Note, the trigger command will
only be execute when at least one add or delete command has succeeded with exit
code 0.Required arguments:
-p Path to directoy to watch for changes.
-a Command to execute when a directory was added.
You can also append the following placeholders to your command string:
%p The full path of the directory that changed (added, deleted).
%n The name of the directory that changed (added, deleted).
Example: -a "script.sh -f %p -c %n -a %p"
-d Command to execute when a directory was deletd.
You can also append the following placeholders to your command string:
%p The full path of the directory that changed (added, deleted).
%n The name of the directory that changed (added, deleted).
Example: -d "script.sh -f %p -c %n -a %p"Optional arguments:
-e Exclude regex for directories to ignore.
E.g.: -e '\.*' to ignore dot directories.
-t Command to execute after all directories have been added or
deleted during one round.
No argument will be appended.
-w The directory watcher to use. Valid values are:
'inotify': Uses inotifywait to watch for directory changes.
'bash': Uses a bash loop to watch for directory changes.
The default is to use 'bash' as the watcher.
-i When using the bash watcher, specify the interval in seconds
for how often to look for directory changes.
-v Verbose output.
-c Colorized log output.Misc arguments:
--help Show this help screen.
--version Show version information.
```### License
**[MIT License](LICENSE)**
Copyright (c) 2017 [cytopia](https://github.com/cytopia)