Guide : Auto removal of downloads from transmission 2.82

Hi,

This script will allow the auto removal of downloaded/completed torrents from transmission bittorrent daemon on my cloud. Note, I did not originally write the script, but I’ve debugged it and fixed a couple of things to make it work in my installation.

 Script Name:  transmission-purge-completed.sh

 

#!/bin/sh

# the folder to move completed downloads to

# port, username, password
SERVER="9091 --auth transmission:transmission"

# 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 $SERVER --list | sed -e '1d;$d;s/^ *//' | cut --only-delimited --delimiter=" " --fields=1`

transmission-remote $SERVER --list 

# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
    echo Processing : $TORRENTID 

    # check if torrent download is completed
    DL_COMPLETED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep "Percent Done: 100%"`

    # check torrents current state is
    STATE_STOPPED=`transmission-remote $SERVER --torrent $TORRENTID --info | grep "State: Seeding\|Stopped\|Finished\|Idle"`
    echo $STATE_STOPPED

    # 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 "Removing torrent from list"
        transmission-remote $SERVER --torrent $TORRENTID --remove
    else
        echo "Torrent #$TORRENTID is not completed. Ignoring."
    fi
done

of note in the above script is this : 

SERVER="9091 --auth transmission:transmission"

This sets the username password and port your transmission daemon is running on. Change this to match your server.

* login via ssh into you my cloud

* stop transmission daemon 

/etc/init.d/transmission-daemon stop

Once changed are made,

place the script in location on your my cloud.

e.g   “/DataVolume/shares/scripts/transmission-purge-completed.sh”

it could even in   /root if you wanted 

make sure the script has the executable permission

chmod +x /DataVolume/shares/scripts/transmission-purge-completed.sh

then edit the transmission json settings file

nano /var/lib/transmission-daemon/info/settings.json

change these 2 lines 

“script-torrent-done-enabled”: true,
“script-torrent-done-filename”: “/DataVolume/shares/scripts/transmission-purge-completed.sh”,

where  “script-torrent-done-filename” matchs the path to the above script

* start transmission daemon 

/etc/init.d/transmission-daemon start

and test via downloading a (small) torrent file.

2 Likes

Nice info.

Thanks for sharing

This is very useful! Didn’t know this was possible.

One question though, why does the script itself needs to check whether the torrent has been fully downloaded? Isn’t that the whole purpose of the  script-torrent-done-enabled  and  script-torrent-done-filename  variables in the settings.json file? That a script will be run at completion…

Well, theres actually a much simpler script that can accomplish the same. save the below two lines in a script .sh file.

the other steps to enable running script after torrent downloads are the same as OP suggested.

Below, 9091 is the port on which you are running transmission. 9091 is the default one.

#!/bin/bash

/usr/bin/transmission-remote 127.0.0.1:9091 -l | grep 100% | awk ‘{print $1}’ | xargs -n 1 -I % /usr/bin/transmission-remote 127.0.0.1:9091 -t % -r

One question though, why does the script itself needs to check whether the torrent has been fully downloaded? Isn’t that the whole purpose of the script-torrent-done-enabled and script-torrent-done-filename variables in the settings.json file? That a script will be run at completion…

 

True, I however did labled the script purge which will remove all completed/seeding/stoppped 100% downloaded files from transmission. So you can run it at any time or independantly if your so inclined.

It is what it is, and it works even if it is over kill.

Ok thanks. The big advantage this way is that you have more control on what is happening and when.

This sure beats my method involving a PHP script which I had running periodically as cron!

1 Like

Hi,

first, thank you for creating free scripts that we all can use.

That said, i am getting an error i do not know how to resolve:

“cut: unrecognized option ‘–only-delimited’”

Entire lines:

"cut: unrecognized option ‘–only-delimited’
BusyBox v1.16.1 (2014-05-29 11:41:56 CST) multi-call binary.

Usage: cut [OPTIONS] [FILE]…

Print selected fields from each input FILE to stdout

Options:
-b LIST Output only bytes from LIST
-c LIST Output only characters from LIST
-d CHAR Use CHAR instead of tab as the field delimiter
-s Output only the lines containing delimiter
-f N Print only these fields
-n Ignored"

Any chance to help?

Thank you

fernmac wrote:

Hi,

first, thank you for creating free scripts that we all can use.

That said, i am getting an error i do not know how to resolve:

“cut: unrecognized option ‘–only-delimited’”

 

Although I think it shoudn’t reproduce that error, I’m going to ask it anyway…

Did you press Enter after the *–only-delimited --" part? There’s no Enter in the script, the line below should be directly after the *–only-delimited --" part

Better and easy:

/etc/transmission-daemon/settings.json

"ratio-limit-enabled": true, 
	"ratio-limit": 1, 
	"scrape-paused-torrents-enabled": false, 
	"trash-original-torrent-files": true, 
	"dht-enabled": false,
	"pex-enabled": false,

WD going to sleep after downloading and seeding file once.

You are using BusyBox which does not support the full command set for the  cut  utility.

Change this line:

TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d;$d;s/^ *//' | cut --only-delimited --delimiter=" " --fields=1`

to this:

TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f 1`

All you are doing is replacing:

--only-delimited --delimiter=" " --fields=1`

with the busybox equivalent

-s -d " " -f 1`

Hope that helps!

This does exactly the same thing:

#!/bin/sh

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

Would this be applicable for transmission 2.92 version?

Can someone tell me how I could run this on windows. I have tried multiple reconfigs.

Hi all!

With the new update to OS 5, now I use Transmission, and I found this very interesting thread.

My problem is when the command “transmission-remote ” is executed, appears this message:

/lib/libcurl.so.4: no version information available (required by transmission-remote)
Unexpected response: 301: Moved Permanently

Any ideas to solve it?

Thank you in advance!