Skip to content

Instantly share code, notes, and snippets.

@butlerpeter
Created February 28, 2017 09:45
Show Gist options
  • Save butlerpeter/30a4ca58735fe5f1c2ac7057cde6431d to your computer and use it in GitHub Desktop.
Save butlerpeter/30a4ca58735fe5f1c2ac7057cde6431d to your computer and use it in GitHub Desktop.
Script to remove torrents from transmisison when done. Based on https://community.wd.com/t/guide-auto-removal-of-downloads-from-transmission-2-82/93156
#!/bin/sh
# the folder to move completed downloads to
# port, username, password
SERVER="9091 --auth user:password"
# 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 | sed 's/\([0-9]*\).*/\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%"`
# echo $DL_COMPLETED
# 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 [ ! -z "$DL_COMPLETED" ] && [ ! -z "$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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment