adhocify/README.md

135 lines
4.4 KiB
Markdown
Raw Permalink Normal View History

2017-03-19 10:42:12 +01:00
What is adhocify?
=================
2017-07-30 10:45:10 +02:00
2017-03-19 10:42:12 +01:00
adhocify uses inotify to watch for file system events. Once an event
occurs it can execute a command. The path of the file and the event
will be passed to that command.
2017-07-30 10:45:10 +02:00
2017-03-19 10:42:12 +01:00
Options
=======
See adhocify --help.
Examples:
=========
```
2017-03-19 10:42:12 +01:00
adhocify -w /tmp/ /home/user/myscript.sh
```
Watches for IN\_CLOSE\_WRITE events in /tmp/ and launches script /home/user/myscript.sh
2017-03-19 10:42:12 +01:00
```
adhocify -w /tmp/ -w /var/run /home/user/myscript.sh
```
Same as above, but also watches /var/run
2017-03-19 10:42:12 +01:00
```
2017-03-19 10:42:12 +01:00
adhocify /home/user/myscript.sh
```
Watches for IN\_CLOSE\_WRITE events in the current directory, launches script /home/user/myscript.
2017-03-19 10:49:58 +01:00
```
adhocify -m IN_OPEN -w /tmp /home/user/myscript.sh
```
Watches for IN\_OPEN events in /tmp/, launches script /home/user/myscript.sh
2017-03-19 10:49:58 +01:00
```
2017-03-19 10:42:12 +01:00
adhocify -w /tmp -i *.txt /home/user/myscript.sh
```
Watches for IN\_CLOSE\_WRITE events in /tmp/ but will not pass any events for *.txt files to the script
2017-03-19 10:49:58 +01:00
```
2017-07-30 10:45:10 +02:00
find . -type d | adhocify -s /home/user/myscript.sh
```
Starts monitoring every subdirectory of the current path for IN\_CLOSE\_WRITE events. However, inotify has limits, thus it may not always work, e. g. when inotify descriptors are being used by other programs or the tree is too large. Therefore adhocify will exit
if it cannot setup a watch for all supplied directories. See inotify(7), /proc/sys/fs/inotify/.
2019-04-27 22:44:50 +02:00
### Child exit codes
```
adhocify -m IN_CREATE --exit-with-child=0 -- /usr/bin/test -f awaited_file
```
Keep running until the file named "awaited_file" is created in the current directory.
`--exit-with-child` also supports negation, so e. g. with `--exit-with-child='!0'` adhocify would keep running as long as the child commands exits with 0.
### Passing event data to the command
```
adhocify -w /tmp/ -w /var/run /home/user/myscript.sh {}
```
Passes the full path of the file an event occured on to the specified command. It can be retreived from argv[1] in the called command.
```
adhocify -w /tmp/ echo the file {} was written to
```
Running echo "Test" > /tmp/test will print in the shell adhocify was launched in: "the file /tmp/test was written to"
```
adhocify -m IN_CREATE -m IN_CLOSE_WRITE -w /path -- /bin/env
```
adhocify passes the inotify event to the command as an environment variable. The variable is called ```ADHOCIFYEVENT``` and contains the value of inotify_event->mask as set by inotify.
#### Receiving events as strings
You can also get a string of the inotify events. This is particularly useful if you have a shellscript and don't want to interpret the ```ADHOCIFYEVENT``` variable yourself
```
echo "test" > /tmp/test
adhocify -m IN_ALL_EVENTS -w /tmp/test echo File: "%eventfilepath%" Event: "%eventmaskstr%"
Starting execution of command echo
File: /tmp/test Event: IN_ATTRIB
Starting execution of command echo
Starting execution of command echo
Starting execution of command echo
File: /tmp/test Event: IN_OPEN
File: /tmp/test Event: IN_CLOSE,IN_CLOSE_WRITE
File: /tmp/test Event: IN_MODIFY
```
A second shell ran
```
chmod 600 /tmp/test
echo "test" >> /tmp/test
```
Passing ```-q``` would also keep adhocify silent, surpressing those "Starting execution..." messages.
2019-04-27 22:44:50 +02:00
Other tools
===========
If adhocify does not suit your needs, take a look at:
* inotify-tools: https://github.com/inotify-tools/inotify-tools/wiki
2020-08-19 11:48:26 +02:00
Install
=======
## Debian / Ubuntu
Latest release can be installed using apt
```
# First, obtain key, assume it's trusted.
wget -O- https://repo.quitesimple.org/repo.quitesimple.org.asc | gpg --dearmor > repo.quitesimple.org-keyring.gpg
cat repo.quitesimple.org-keyring.gpg | sudo tee -a /usr/share/keyrings/repo.quitesimple.org.gpg > /dev/null
#For Debian
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/repo.quitesimple.org.gpg] https://repo.quitesimple.org/debian/ default main" | sudo tee /etc/apt/sources.list.d/quitesimple.list
#For Ubuntu >=21.10, prefer these sources
#echo "deb [arch=amd64 signed-by=/usr/share/keyrings/repo.quitesimple.org.gpg] https://repo.quitesimple.org/debian/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/quitesimple.list
2020-08-19 11:48:26 +02:00
sudo apt-get update
sudo apt-get install adhocify
```
## Alpine
```
wget https://repo.quitesimple.org/repo%40quitesimple.org-5f3d101.rsa.pub -O /etc/apk/repo@quitesimple.org-5f3d101.rsa.pub
echo "https://repo.quitesimple.org/alpine/quitesimple/" >> /etc/apk/repositories
apk update
apk add adhocify
```
2020-08-19 11:48:26 +02:00
## Other
To install from source, run
```
make install
```
which will place adhocify in /usr/local/bin/