Transmission, move completed downloads/torrents
I wanted to be able to move torrents that were completed and had a stopped state. (Which would occur when you stop them from the interface or when the seed ratio has been met) I was inspired by this script. I fixed it a bit and I am now using it to move completed torrents from my SSD to my larger platter based disks so that I don’t have to keep them spinning while downloading/uploading. I first used awk to get the columns but then switched to cut. Use whatever you like or just copy-paste and modify the MOVEDIR and BASE_COMMAND params. Make sure that the user transmission is running on has write permissions on the folder the data is moved to.
#!/bin/sh MOVEDIR=/mnt/share BASE_COMMAND="transmission-remote -n yourusername:yourpassword" TORRENT_ID_LIST=$($BASE_COMMAND -l | sed -e '1d;$d;s/^ *//' | cut -d ' ' -f 1) for TORRENT_ID in $TORRENT_ID_LIST do NAME=$($BASE_COMMAND -t $TORRENT_ID -i | grep -i "Name:" | sed 's/^ *//' | cut -d ' ' -f 2-) PERCENT_COMPLETE=$($BASE_COMMAND -t $TORRENT_ID -i | grep -i "Percent Done:" | sed 's/^ *//' | cut -d ' ' -f 3) STATE=$($BASE_COMMAND -t $TORRENT_ID -i | grep -i "State:" | sed 's/^ *//' | cut -d ' ' -f 2) RATIO=$($BASE_COMMAND -t $TORRENT_ID -i | grep -i "Ratio:" | sed 's/^ *//' | cut -d ' ' -f 2) #echo "$NAME:$PERCENT_COMPLETE:$STATE:$RATIO" if [ "$PERCENT_COMPLETE" = "100%" ] && ( [ "$STATE" = "Stopped" ] || [ "$STATE" = "Finished" ] ); then echo "Torrent $NAME is completed" $BASE_COMMAND -t $TORRENT_ID --move $MOVEDIR $BASE_COMMAND -t $TORRENT_ID -r echo "\tTorrent data moved and removed from transmission" fi done |
Thanks for sharing Wytze !
Based on your script I just modified the condition as follows since one (at least I) might want to move the received files as soon as they’re complete and remove them later, according to the same scheme as yours…
if [ “$PERCENT_COMPLETE” = “100%” ] ; then
echo “$(date) : le torrent $NAME est arrivé” >> /var/log/purgeTorrents.log
$BASE_COMMAND -t $TORRENT_ID –move $MOVEDIR
echo “$(date) : données torrent déplacées dans $MOVEDIR” >> /var/log/purgeTorrents.log
echo “Subject: Arrivée de $NAME” | sendmail -f $EXP $DEST
if ( [ “$STATE” = “Stopped” ] || [ “$STATE” = “Finished” ] ); then
echo “$(date) : le torrent $NAME est arrêté” >> /var/log/purgeTorrents.log
$BASE_COMMAND -t $TORRENT_ID -r
echo “$(date) : données torrent supprimées de transmission” >> /var/log/purgeTorrents.log
fi
fi
I also added the sending of an email from EXP to DEST in order to inform the torrent’s complete. EXP and DEST need to be initalized as for MOVEDIR and BASE_COMMAND. It looks like :
EXP=transmission-hostname
DEST=mail@domain
Nice addition!
Mmh, I was a bit too fast to post, I’m afraid. :o/
This way, completed torrents are moved every time the script is run. So you need to check the “location” before moving and email the torrent’s complete, if it the same as “movedir”, then you already moved it !
BTW, since you’re interested only in completed torrents, you can just list them, excluding any other current torrent ?
Here’s my new version :
[code]#!/bin/sh
MOVEDIR=/media/shared/Downloads
BASE_COMMAND=”transmission-remote”
EXP=mytransmissionhost
DEST=”myuser@mydomain”
TORRENT_ID_LIST=$($BASE_COMMAND -l | sed -e ‘1d;$d;s/^ *//’ | grep ‘100%’ | cut -d ‘ ‘ -f 1)
for TORRENT_ID in $TORRENT_ID_LIST
do
NAME=$($BASE_COMMAND -t $TORRENT_ID -i | grep -i “Name:” | sed ‘s/^ *//’ | cut -d ‘ ‘ -f 2-)
LOC=$($BASE_COMMAND -t $TORRENT_ID -i | grep -i “Location:” | sed ‘s/^ *//’ | cut -d ‘ ‘ -f 2-)
if [ “$LOC” != “$MOVEDIR” ]; then
echo “$(date) : le torrent $NAME est arrivé” >> /var/log/purgeTorrents.log
$BASE_COMMAND -t $TORRENT_ID –move $MOVEDIR
echo “$(date) : données torrent déplacées dans $MOVEDIR” >> /var/log/purgeTorrents.log
echo “Subject: Arrivée de $NAME” | /usr/sbin/sendmail -f $EXP $DEST
fi
STATE=$($BASE_COMMAND -t $TORRENT_ID -i | grep -i “State:” | sed ‘s/^ *//’ | cut -d ‘ ‘ -f 2)
if ( [ “$STATE” = “Stopped” ] || [ “$STATE” = “Finished” ] ); then
echo “$(date) : le torrent $NAME est arrêté” >> /var/log/purgeTorrents.log
$BASE_COMMAND -t $TORRENT_ID -r
echo “$(date) : données torrent supprimées de transmission” >> /var/log/purgeTorrents.log
fi
done[/code]