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.