Transmission-daemon does not automatically remove completed torrents. I created a script to do so, and I run it via a cron job (under my own user ID) on my Ubuntu 10.04 Lucid Lynx Server.
This script uses command line utility transmission-remote (which is installed when you install the transmission-daemon package) to check on the progress of all active torrents. Torrents that have completed downloading and seeding will have a status of “Stopped” and a (download) percent done of “100%”. This script will identify such torrents, move their downloaded files to a different directory, and will remove the torrent from transmission-daemon.
This script depends on using a seeding ratio to stop your torrents from seeding after a certain percentage has been seeded. If your torrents seed indefinitely, transmission-daemon will never stop them, and this script will not know that the torrent is completed.
Note that transmission-daemon has a built-in option to store incomplete downloads in one folder, and move them, when the download completes, to another folder. This script is meant to pick the torrents up afterward, and move them from the download folder to somewhere more permanent. If you just want to remove completed torrents, comment out the line “transmission-remote --torrent $TORRENTID --netrc $NETRC --move $MOVEDIR“.
Script: movecompletedtorrents
This script is a modified version of the one found at http://forum.qnap.com/viewtopic.php?f=45&t=25553.
#!/bin/sh
# script to check for complete torrents in transmission folder, then stop and move them
MOVEDIR=/home/user/media
NETRC=/home/user/.netrc
# get torrent list from transmission-remote list
# delete first / last line of output
# remove leading spaces
# get first field from each line
TORRENTLIST=`transmission-remote --list --netrc $NETRC | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f1`
# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
echo "* * * * * Operations on torrent ID $TORRENTID starting. * * * * *"
# check if torrent was started
STARTED=`transmission-remote --torrent $TORRENTID --info --netrc $NETRC | grep "Id: $TORRENTID"`
# echo " - started state = $STARTED" # debug message
# check if torrent download is completed
COMPLETED=`transmission-remote --torrent $TORRENTID --info --netrc $NETRC | grep "Percent Done: 100%"`
# echo " - completed state = $COMPLETED" # debug message
# check torrent's current state is "Stopped"
STOPPED=`transmission-remote --torrent $TORRENTID --info --netrc $NETRC | grep "State: Stopped"`
# echo " - torrent stopped seeding = $STOPPED" # debug message
# if the torrent is "Stopped" after downloading 100% and seeding, move the files and remove the torrent from Transmission
if [ "$STARTED" != "" ] && [ "$COMPLETED" != "" ] && [ "$STOPPED" != "" ]; then
echo "Torrent #$TORRENTID is completed."
echo "Moving downloaded file(s) to $MOVEDIR."
transmission-remote --torrent $TORRENTID --netrc $NETRC --move $MOVEDIR
echo "Removing torrent from list."
transmission-remote --torrent $TORRENTID --netrc $NETRC --remove
else
echo "Torrent #$TORRENTID is not completed. Ignoring."
fi
echo "* * * * * Operations on torrent ID $TORRENTID completed. * * * * *"
done
Scheduling
To run this script every hour, save the script somewhere (/home/user/bin), grant yourself permission to execute it…
$ chmod u+x ~/bin/movecompletedtorrents
…edit your crontab settings…
$ crontab -e
…and add the following line.
@hourly /home/user/bin/movecompletedtorrents