Skip to content

Instantly share code, notes, and snippets.

@root-hal9000
Forked from bulljit/removecompletedtorrents.sh
Created September 29, 2019 19:38
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save root-hal9000/6c9fb792fce4af0c4cb561fd653c86b6 to your computer and use it in GitHub Desktop.
Save root-hal9000/6c9fb792fce4af0c4cb561fd653c86b6 to your computer and use it in GitHub Desktop.
Transmission-Daemon: Remove Completed Torrents
#!/bin/bash
# script to check for complete torrents in transmission folder, then stop and move them
# either hard-code the MOVEDIR variable here…
MOVEDIR=/data/complete
USER=YOUR_USER_NAME
PASS=YOUR_PASS
# use transmission-remote to get torrent list from transmission-remote list
# use sed to delete first / last line of output, and remove leading spaces
# use cut to get first field from each line
TORRENTLIST=`transmission-remote -n $USER:$PASS --list | sed -e '1d;$d;s/^ *//' | cut --only-delimited -d ' ' --fields=1`
# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
TORRENTID=`echo $TORRENTID | sed 's:*::'`
# removes asterisk * from torrent ID# which had error associated with it
echo "* * * * * Operations on torrent ID $TORRENTID starting. * * * * *"
# check if torrent download is completed
DL_COMPLETED=`transmission-remote -n $USER:$PASS -t $TORRENTID -i | grep "Percent Done: 100%"`
# check torrent’s current state is "Stopped", "Finished", or "Idle"
STATE_STOPPED=`transmission-remote -n $USER:$PASS -t $TORRENTID -i | grep "State: Stopped\|Finished\|Idle"`
# if the torrent is "Stopped", "Finished", or "Idle" after downloading 100%…
if [ "$DL_COMPLETED" != "" ] && [ "$STATE_STOPPED" != "" ]; then
# move the files and remove the torrent from Transmission
echo "Torrent $TORRENTID is completed."
echo "Moving downloaded files to $MOVEDIR."
transmission-remote -n $USER:$PASS -t $TORRENTID -m $MOVEDIR
echo "Removing torrent from list."
transmission-remote -n $USER:$PASS -t $TORRENTID -r
else
echo "Torrent $TORRENTID is not completed. Ignoring."
fi
echo "* * * * * Operations on torrent ID $TORRENTID completed. * * * * *"
done
@root-hal9000
Copy link
Author

  • Fixed several small issues to make the code work
  • added authentication for password protected Transmission Web UI

@root-hal9000
Copy link
Author

If your web UI is not password protected, just remove the "-n $USER:$PASS" from all commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment