Skip to content

Instantly share code, notes, and snippets.

@amussey
Forked from daktak/removecompletedtorrents.sh
Last active August 29, 2015 14:14
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 amussey/1347d65b709388a565a2 to your computer and use it in GitHub Desktop.
Save amussey/1347d65b709388a565a2 to your computer and use it in GitHub Desktop.
#!/bin/sh
# script to check for complete torrents in transmission folder, then stop and move them
# either hard-code the MOVEDIR variable here?
# ?or set MOVEDIR using the first command-line argument
# MOVEDIR=%1
# 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 --list | sed -e '1d;$d;s/^ *//' | cut -s -d ' ' -f1 `
# for each torrent in the list
for TORRENTID in $TORRENTLIST
do
TORRENTID=`echo "$TORRENTID" | sed 's:*::'`
# removes asterisk * from torrent ID# which had error associated with it
echo "* * * * * Operations on torrent ID $TORRENTID starting. * * * * *"
# check if torrent download is completed
DL_COMPLETED=`transmission-remote --torrent $TORRENTID --info | grep "Percent Done: 100%"`
# check torrent's current state is "Stopped", "Finished", or "Idle"
STATE_STOPPED=`transmission-remote --torrent $TORRENTID --info | grep "State: Stopped\|Finished\|Idle\|Seeding"`
# if the torrent is "Stopped", "Finished", or "Idle" after downloading 100%?
MOVEDIR=`transmission-remote --torrent $TORRENTID --info | grep "Location:" | sed s/\ \ Location:\ // | sed s/-incomplete//`
MOVEDIR="${MOVEDIR}-complete"
if [ "$DL_COMPLETED" != "" ] && [ "$STATE_STOPPED" != "" ]; then
# move the files and remove the torrent from Transmission
echo "Torrent #$TORRENTID is completed."
echo "Moving downloaded file(s) to $MOVEDIR."
transmission-remote --torrent $TORRENTID --move $MOVEDIR
chmod -R a+rwx $MOVEDIR/*
echo "Removing torrent from list."
transmission-remote --torrent $TORRENTID --remove
else
echo "Torrent #$TORRENTID is not completed. Ignoring."
fi
echo "* * * * * Operations on torrent ID $TORRENTID completed. * * * * *"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment