Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamhancock/510a2def5907e75f35a5c499ef382514 to your computer and use it in GitHub Desktop.
Save adamhancock/510a2def5907e75f35a5c499ef382514 to your computer and use it in GitHub Desktop.
Script to clear finished torrents from transmission-daemon
#!/bin/bash
# port, username, password
SERVER="localhost:9091 --auth user:pass"
# use transmission-remote to get torrent list from transmission-remote list
TORRENTLIST=`transmission-remote $SERVER --list | sed -e '1d' -e '$d' | awk '{print $1}' | sed -e 's/[^0-9]*//g'`
# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
INFO=$(transmission-remote $SERVER --torrent $TORRENTID --info)
echo -e "Processing #$TORRENTID - $(echo $INFO | sed -e 's/.*Name: \(.*\) Hash.*/\1/')"
# check if torrent download is completed
DL_COMPLETED=`echo $INFO | grep "Done: 100%"`
# check torrents current state is
STATE_STOPPED=`echo $INFO | grep "State: Seeding\|State: Stopped\|State: Finished\|State: Idle"`
# if the torrent is "Stopped", "Finished", or "Idle after downloading 100%"
if [ "$DL_COMPLETED" ] && [ "$STATE_STOPPED" ]; then
echo "Torrent #$TORRENTID is completed. 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