Skip to content

Instantly share code, notes, and snippets.

@bulljit
Created January 22, 2011 23:17
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save bulljit/791609 to your computer and use it in GitHub Desktop.
Save bulljit/791609 to your computer and use it in GitHub Desktop.
Transmission-Daemon: Remove Completed Torrents
#!/bin/sh
# script to check for complete torrents in transmission folder, then stop and move them
# either hard-code the MOVEDIR variable here…
MOVEDIR=/home/mjdescy/media # the folder to move completed downloads to
# …or set MOVEDIR using the first command-line argument
# MOVEDIR=%1
# 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 –list | sed -e ’1d;$d;s/^ *//’ | cut –only-delimited –delimiter= ” ” –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 –torrent $TORRENTID –info | grep “Percent Done: 100%”`
# check torrent’s current state is “Stopped”, “Finished”, or “Idle”
STATE_STOPPED=`transmission-remote –torrent $TORRENTID –info | 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 file(s) to $MOVEDIR.”
transmission-remote –torrent $TORRENTID –move $MOVEDIR
echo “Removing torrent from list.”
transmission-remote –torrent $TORRENTID –remove
else
echo “Torrent #$TORRENTID is not completed. Ignoring.”
fi
echo “* * * * * Operations on torrent ID $TORRENTID completed. * * * * *”
done
@fernandog
Copy link

When Transmission runs a script after the download was completed it pass the torrentid:

so why don't you do this:
transmission-remote -t $TORRENTID --move $MOVEDIR
transmission-remote -t $TORRENTID --remove

@drjayvee
Copy link

drjayvee commented Dec 1, 2013

To get the IDs of torrents, why don't you use
transmission-remote –list | grep -Eo '^ *([0-9]+)'

@drjayvee
Copy link

drjayvee commented Dec 1, 2013

Also, transmission-remote -info should be --info or -i

@stef06
Copy link

stef06 commented Nov 6, 2015

you have a simple script for juste erase from list all completed torrent form transmission ?

@NotoriousPyro
Copy link

NotoriousPyro commented Dec 14, 2016

This does exactly the same thing accompanied with the incomplete and complete folder functionality of Transmission (to move them using its built-in functionality):

#!/bin/sh

/usr/bin/transmission-remote -t $TR_TORRENT_ID -r

And then just use this as your post download script in Transmission config.

@jaumard
Copy link

jaumard commented Jan 14, 2017

doesn't seams to work anymore...

@Ryan747800B
Copy link

@scriptzteam Doesn't seem to work

Copy link

ghost commented Mar 31, 2017

is there a way to just delete them after 5 Days of seeding?

@scriptzteam
Copy link

@Ryan747800B what not works ?? be specific please :)

@onedr0p
Copy link

onedr0p commented May 9, 2018

Anyone from google may want to check out https://gist.github.com/onedr0p/8fd8455f08f4781cad9e01a1d65bc34f

@XayOn
Copy link

XayOn commented Mar 30, 2019

Simple bash one-liner:

while read tid percent rest; do [[ "$percent" == "100%" ]] && transmission-remote -t ${tid/*/} -r; done < <(transmission-remote -l)

@root-hal9000
Copy link

@bulljit

I forked then debugged and fixed the code to work on my SYnology NAS, transmission running inside Docker, in particular this container from @haugene. It was mostly small issues with parameters and quotes
I also added password authentication in case you have your Web UI password protected. If you don't, just remove the "-n $USER:$PASS" from all commands. I am using this to be triggered every time a torrent completes

Here it is:
https://gist.github.com/ffcruz85/6c9fb792fce4af0c4cb561fd653c86b6

@root-hal9000
Copy link

The torrent files don't get moved to that folder on mine, but since I mostly had magnet links, it doesn't matter to me as long as it keeps removing from the torrent list.

@applebait
Copy link

Simple bash one-liner:

while read tid percent rest; do [[ "$percent" == "100%" ]] && transmission-remote -t ${tid/*/} -r; done < <(transmission-remote -l)

And where should we set this line? Just an sh running on a crontab? For instance I have this workflow where I run a watch command on transmission-remote -l which is showing me all the torrents and their progress. How can I fit this shell command you provide us? Can you kindly tell us? :)

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