executes commands upon file system events (using inotify)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. What is adhocify?
  2. =================
  3. adhocify uses inotify to watch for file system events. Once an event
  4. occurs it can execute a command. The path of the file and the event
  5. will be passed to that command.
  6. Options
  7. =======
  8. See adhocify --help.
  9. Examples:
  10. =========
  11. ```
  12. adhocify -w /tmp/ /home/user/myscript.sh
  13. ```
  14. Watches for IN\_CLOSE\_WRITE events in /tmp/ and launches script /home/user/myscript.sh
  15. ```
  16. adhocify -w /tmp/ -w /var/run /home/user/myscript.sh
  17. ```
  18. Same as above, but also watches /var/run
  19. ```
  20. adhocify /home/user/myscript.sh
  21. ```
  22. Watches for IN\_CLOSE\_WRITE events in the current directory, launches script /home/user/myscript.
  23. ```
  24. adhocify -m IN_OPEN -w /tmp /home/user/myscript.sh
  25. ```
  26. Watches for IN\_OPEN events in /tmp/, launches script /home/user/myscript.sh
  27. ```
  28. adhocify -w /tmp -i *.txt /home/user/myscript.sh
  29. ```
  30. Watches for IN\_CLOSE\_WRITE events in /tmp/ but will not pass any events for *.txt files to the script
  31. ```
  32. find . -type d | adhocify -s /home/user/myscript.sh
  33. ```
  34. 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
  35. if it cannot setup a watch for all supplied directories. See inotify(7), /proc/sys/fs/inotify/.
  36. ### Child exit codes
  37. ```
  38. adhocify -m IN_CREATE --exit-with-child=0 -- /usr/bin/test -f awaited_file
  39. ```
  40. Keep running until the file named "awaited_file" is created in the current directory.
  41. `--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.
  42. ### Passing event data to the command
  43. ```
  44. adhocify -w /tmp/ -w /var/run /home/user/myscript.sh {}
  45. ```
  46. 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.
  47. ```
  48. adhocify -w /tmp/ echo the file {} was written to
  49. ```
  50. Running echo "Test" > /tmp/test will print in the shell adhocify was launched in: "the file /tmp/test was written to"
  51. ```
  52. adhocify -m IN_CREATE -m IN_CLOSE_WRITE -w /path -- /bin/env
  53. ```
  54. 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.
  55. #### Receiving events as strings
  56. 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
  57. ```
  58. echo "test" > /tmp/test
  59. adhocify -m IN_ALL_EVENTS -w /tmp/test echo File: "%eventfilepath%" Event: "%eventmaskstr%"
  60. Starting execution of command echo
  61. File: /tmp/test Event: IN_ATTRIB
  62. Starting execution of command echo
  63. Starting execution of command echo
  64. Starting execution of command echo
  65. File: /tmp/test Event: IN_OPEN
  66. File: /tmp/test Event: IN_CLOSE,IN_CLOSE_WRITE
  67. File: /tmp/test Event: IN_MODIFY
  68. ```
  69. A second shell ran
  70. ```
  71. chmod 600 /tmp/test
  72. echo "test" >> /tmp/test
  73. ```
  74. Passing ```-q``` would also keep adhocify silent, surpressing those "Starting execution..." messages.
  75. Other tools
  76. ===========
  77. If adhocify does not suit your needs, take a look at:
  78. * inotify-tools: https://github.com/inotify-tools/inotify-tools/wiki
  79. Install
  80. =======
  81. ## Debian / Ubuntu
  82. Latest release can be installed using apt
  83. ```
  84. curl -s https://repo.quitesimple.org/repo.quitesimple.org.asc | sudo apt-key add -
  85. echo "deb https://repo.quitesimple.org/debian/ default main" | sudo tee /etc/apt/sources.list.d/quitesimple.list
  86. sudo apt-get update
  87. sudo apt-get install adhocify
  88. ```
  89. ## Alpine
  90. ```
  91. wget https://repo.quitesimple.org/repo%40quitesimple.org-5f3d101.rsa.pub -O /etc/apk/repo@quitesimple.org-5f3d101.rsa.pub
  92. echo "https://repo.quitesimple.org/alpine/quitesimple/" >> /etc/apk/repositories
  93. apk update
  94. apk add adhocify
  95. ```
  96. ## Other
  97. To install from source, run
  98. ```
  99. make install
  100. ```
  101. which will place adhocify in /usr/local/bin/