[HOWTO] Automated torrent removal with Transmission

Status
Not open for further replies.

codenamezero

Explorer
Joined
Sep 4, 2011
Messages
59
STEP 1
Install Transmission, follow one of the online Transmission guide and note down the following...

Code:
freenas# cat /conf/base/etc/rc.d/transmission
#!/bin/sh
. /etc/rc.subr

name="transmission"
rcvar=${name}_enable

command=/usr/local/bin/transmission-daemon

load_rc_config ${name}

: ${transmission_enable:="YES"}
: ${transmission_user:="root"}
: ${transmission_conf_dir:="/mnt/FREENAS/torrent/conf"}
: ${transmission_download_dir:="/mnt/FREENAS/torrent"}

transmission_flags=" \
        ${transmission_watch_dir:+-c ${transmission_watch_dir}} \
        ${transmission_conf_dir:+-g ${transmission_conf_dir}} \
        ${transmission_download_dir:+-w ${transmission_download_dir}} \
        ${transmission_flags}"

run_rc_command "$1"


We will need those 2 paths later on, but that's how I setup mine.

STEP 2
Decide on a location where you want to put the automated torrent removal scripts. I decided to put it here...

Code:
freenas# pwd
/mnt/FREENAS/torrent/bin
freenas# ls -rtl
total 6
-rw-r--r--  1 root  www   27 Sep  3 01:24 set_env
-rwxr-xr-x  1 root  www  240 Sep  6 23:08 get_torrents_by_percentage
-rwxr-xr-x  1 root  www  171 Sep  6 23:08 get_torrents_by_ratio
-rwxr-xr-x  1 root  www  354 Sep  8 01:11 rm_completed_bt.sh


These are the contents of my scripts:
Set environment script
Code:
freenas# cat set_env
# Where transmission-remote is located
PATH=$PATH:/usr/local/bin
# Where the automated scripts are located
BINPATH=/mnt/FREENAS/torrent/bin
# Username and password for your Transmission
username=<Your Transmission login name>
password=<Your Transmission password>


Helper script
Code:
freenas# cat get_torrents_by_percentage
#!/bin/sh
. set_env

if [ "$1" != "" ]
then
   transmission-remote -n $username:$password -l | grep $1 | cut -c 1-5 -c 71-
else
   echo "Usage: $0 <0-100>"
fi


Torrent removal script
Code:
freenas# cat rm_completed_bt.sh
#!/bin/sh
. set_env

cd $BINPATH

torrents=`./get_torrents_by_percentage 100`

IFS="
"

#echo "Running rm_completed_bt.sh"
for torrent in $torrents;
do
   id=`echo $torrent | awk '{ print $1 }'`
   echo "Removing torrent ID# $torrent"
   transmission-remote -n $username:$password -t $id -r
done


You can test to see if the script is working or not by manually running ./rm_completed_bt.sh, just make sure your Transmission had a completed torrent sitting there seeding. If it works, you should see something like this on the screen:

Code:
freenas# /mnt/FREENAS/torrent/bin/rm_completed_bt.sh
Removing torrent ID#    1 [UTW]_Appleseed_XIII_-_02_[BD][h264-720p_FLAC][E8D09710].mkv
localhost:9091 responded: "success"


STEP 3
Next step is to set it up in cron, if you are running 8.01 Beta, you can probably set it up using the WebGUI, however, I did it in 8.0 and I don't plan on upgrading it so here is how to do it... took me a while to figure it out.

Basically you need to edit /conf/base/var/cron/tab/root
However, the syntax is a little different, you don't need to specify the username...
So, lets go ahead and do mount -uw / so that you can create and edit the file /conf/base/var/cron/tab/root

Put the following in the root file (you will need to manually create the root file)
Code:
#
# $FreeBSD: src/etc/crontab,v 1.33.2.1 2009/08/03 08:13:06 kensmith Exp $
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/mnt/FREENAS/torrent/bin
# Remove completed torrent from Transmission
*/30    *       *       *       *       rm_completed_bt.sh >> /mnt/FREENAS/torrent/bin/cron.log 2>>&1


Reboot, and after it finish rebooting type the following:
Code:
freenas# crontab -l
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/mnt/FREENAS/torrent/bin
# Remove completed torrent from Transmission
*/30    *       *       *       *       rm_completed_bt.sh >> /mnt/FREENAS/torrent/bin/cron.log


You should see the cron job is being loaded in the list.

PS: The log file is optional, you can simply comment it out from the script.

Cheers!
 

ProtoSD

MVP
Joined
Jul 1, 2011
Messages
3,348
Nice job, I think in Step 3 you mean 8.01. Thanks for struggling to figure it out and posting your results!
 

codenamezero

Explorer
Joined
Sep 4, 2011
Messages
59
Nice job, I think in Step 3 you mean 8.01. Thanks for struggling to figure it out and posting your results!

Yea 8.01, fixed. :)

PS: I think people could still use the scripts, since the crontab feature in 8.0.1 only allow people to add a job (not sure if they could upload scripts through the GUI or what not).
 

codenamezero

Explorer
Joined
Sep 4, 2011
Messages
59
Reinstalled my FreeNAS again lol, messed it up while I tried to hack Transmission to allow me to upload file through the GUI.
I was trying to follow my own guide and turns out i had a mistake. Corrected my mistake in the first post.

/conf/base/var/tab/root should be /conf/base/var/cron/tab/root
 

stevetoza

Dabbler
Joined
Jan 6, 2017
Messages
20
Hello,

Does this guide still work in the latest version of freenas? if it does will it still remove the completed torrents if they are not seeded.

Thanks
 
Status
Not open for further replies.
Top