DNS-323 + Transmission — Stop seeding after 100% ratio
Published April 5th, 2009 in dns-323, hacks, unix
Reader Kolonel2 to the rescue with a much-requested feature — A script that stops Transmission seeding once it’s seeded to 100%. Sharing is caring, people!
To use, copy and paste the script below into a file, e.g. tdrmseed.sh, and add it to cron with whatever interval you want it to run on (see previous posts on editcron.sh).
#!/bin/sh
#################################################
#
# tdrmseed : a Transmission daemon script
# -- stopping DONE + Seeded ratio >= 1
#
# For the DNS-323
# Kolonel2, 03/29/2009
#
# Notes:
# - ratio is read as a single digit (not float)
# - torrents that have ratio >= 1 but are not "seeding"
# are not removed (they are "idle")
#
#################################################
PATH='/ffp/sbin:/ffp/bin:/usr/sbin:/sbin:/usr/bin:/bin'
TRANS=/ffp/bin/transmission-remote
TRANSDIR=/mnt/HD_a2/.transmission-daemon
TORFILE=$TRANSDIR/tdrs.list
LOGFILE=$TRANSDIR/tdrs.log
# Output current torrents to a file
$TRANS -l > $TORFILE
while read inputline
do
# Setup variables from each line of the file
done="$(echo $inputline | cut -d" " -f 2)"
id="$(echo $inputline | cut -d" " -f 1)"
ratio="$(echo $inputline | cut -d" " -f 8 | cut -b1)"
name="$(echo $inputline | cut -d" " -f 10-13)"
status="$(echo $inputline | cut -d" " -f 9)"
# Check if current line contains a torrent that is "100%" done
if [ $done = "100%" ]; then
if [ $ratio -ge 1 ]; then
if [ $status = "Seeding" ]; then
echo `date` - stop $id [ $name ] >> $LOGFILE
$TRANS -t $id --stop
fi
fi
fi
done < $TORFILE
Next, don’t forget to comment out the section in my original torrentwatchdog.sh script that stops completed downloads. (Just put a “#” character in front of the line 28, like this: # $TRANSMISSION_REMOTE -t $i -S
Thanks!
I get the following error when running the script:
sh: [: bad number
Any ideas?
There is a problem with the line:
if [ $ratio -ge 1 ]; then
that causes the error “bad number”. For my purpose I simply commented this line out, since I need only 2 conditions satisfied (done should be 100% & status should be “Seeding”). Of course, remember to comment out one of the “fi” lines too.
Also, note that the line getting the “status” is incorrect: the number inline should be 7, not 9. The line should look like this:
status=”$(echo $inputline | cut -d” ” -f 7)”
Try out these changes and the script should work fine