Transmission container auto-add magnet links

LinuxServer.io provides a docker image for the Transmission torrent client. The client can be configured to watch a directory and add torrents from files placed in that directory. Unfortunately transmission does not pick up torrents from *.magnet files stored in the watch directory.

I wanted a quick way to drop a magnet link info into a *.magnet file and have Transmission pick it up automatically. After some research to see how others have solved this issue I decided to implement this functionality myself. A few things were required to get it working:

  1. A script calling the transmission-remote binary
  2. A cronjob to run the script periodically

The script itself is simple: list the contents of the watch directory - mounted at /watch - and run transmission-remote --add for each file. If the file is a *.magnet file, pass its contents into the command. You can grab the script from here.

Implementing the cronjob was a simple task as well. Here are the steps involved:

  1. Run the command docker exec -ti transmission /bin/bash to connect to the container
  2. In the container shell run crontab -e
  3. Add a job to the list which will call the script periodically. For example to run the script grab-from-watched-folder.sh stored in /config every minute the line will be */1 * * * * /config/grab-from-watched-folder.sh >/dev/null 2>&1
  4. The crontab will be updated after you exit the editor.

That was great great, but I had to go through them each time the container was updated or recreated. Not ideal. To get around this I added the following lines to the script which creates the container:

1printf "\nWaiting for container to startup. Delay 5 seconds\n"
2sleep 5s
3echo "Updating crontab"
4docker exec transmission bash -c "echo '*/1 * * * * /config/grab-from-watched-folder.sh >/dev/null 2>&1' >> /etc/crontabs/root"
5docker exec transmission bash -c "touch /etc/crontabs/cron.update"