Run shell scripts via event hook files (similar to Git hooks) when changes are detected in a Syncthing folder.
npm i -g syncthing-hooks
You can simply run the watcher process via:
Don't forget to substitute
mykey with your syncthing API key, which can be found in the settings in the GUI.
If Syncthing runs on another host or listens to a non-default port, you can specify an URL by using
Note that this URL has to include the protocol, hostname, port and path, e.g.:
It won't install itself as a daemon by default, however. In order to run it as a service, it is recommended to install pm2:
npm i -g pm2
You can then register it as a daemon via:
pm2 start "API_KEY=mykey syncthing-hooks" --name sthooks
To create the daemon automatically on startup, consult this documentation.
You can follow the output of your hooks by using:
Create a folder in your home directory called
A different directory can be set using
Each hook is a file with the following naming scheme:
The folder name is the 11 character unique string found in the syncthing GUI. The delay is a string (anything parseable by the ms module) indicating the idle time after an event, so that hooks aren't executed multiple times on successive changes in a short interval.
An example: a script at the location
~/.syncthing-hooks/night-owlzz-5m will be executed five minutes after the most recent event in the folder with the identifier
Don't forget to
chmod +x the script.