Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmcallejo/57f104d9241013930e08432b5c9206a4 to your computer and use it in GitHub Desktop.
Save dmcallejo/57f104d9241013930e08432b5c9206a4 to your computer and use it in GitHub Desktop.
Add magnet files from watch dir to transmission (with authentication, for linuxserver.io docker image)
#!/bin/bash
# Filename: grab-magnets-from-watchdir.custom-cont-init-script
# Save this file in /config/custom-cont-init.d/
# This way it will run everytime the container is created and will add the crontab entry and transmission authentication
# Save env files to get authentication
printenv | sed 's/^\(.*\)$/export \1/g' > /root/container.env
# Add entry to crontab, runs every minute
echo '* * * * * . /root/container.env; /config/grab-magnets-from-watchdir.sh' >> /etc/crontabs/root
#!/usr/bin/env bash
# Filename: grab-magnets-from-watchdir.sh
# Save this file into your /config directory
tr=$(which transmission-remote) # set path for transmission-remote binary
if [ -f /watch/*.magnet ]
then
for t in /watch/*.magnet; do
echo "Adding "$t""
m=$(cat "$t") # get contents of magnet file
$tr -n "$USER:$PASS" --add $m && \
/bin/mv "$t" "$t".added # add to transmission and rename the magnet file
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment