Remove torrents that finished downloading in transmission (WebUI)
Ever found your transmission queue filling up with torrents that have been completed which makes you lose the overview? I have, and coming home to start removing these files was a major waste of time, so I stared writing my first ever Bash script to solve this issue.
First thing you have to do is ensure you have “transmission-remote” installed. For me it was included when I installed transmission on my raspberry pi.
1 2 3 4 5 6 7 |
$ ls /usr/bin/ | grep 'transmission' transmission-cli transmission-create transmission-daemon transmission-edit transmission-remote transmission-show |
Once you have verified you have this installed you can continue with the creation of the script. Create a new file using you favorite text editor (for example “nano”) and paste the following code:
1 2 3 4 5 6 7 8 9 10 11 12 |
#!/bin/bash TORRENTLIST=$(transmission-remote -l | grep 'Finished' 2>&1) while read -r line; do TORRENTID=${line:0:5} TORRENTID=${TORRENTID//\*} TORRENTID=${TORRENTID//[[:blank:]]/} transmission-remote localhost -t $TORRENTID -r echo "Removing $TORRENTID from list $OUTPUT" done <<< "$TORRENTLIST" echo "Operations completed." |
This is assuming you are running transmission and this script on the same server, and transmission-daemon is listening on localhost:9091. For other hosts/ports you need to pass additional parameters to the transmission-remote command.
Now that you have your script in place, remember to call it using crontab. In below example it is getting called once a day at noon.
1 |
0 12 * * * pi bash /home/pi/transmissionCleanup.sh |
The reason I am using this instead of the ability to call a script once a download completes, is because I had to clean up a whole chunk of backlog torrents that were still in my queue. This script will clean up ALL torrents that have status “Finished” once a day.
Note: In case your torrents never have status “Finished”, this will not work. Torrents are only set to status Finished if they are not seeding or downloading anymore. This can be forced in transmission by changing the options under “Seeding”.