Skip to content

Instantly share code, notes, and snippets.

@hampusn
Last active June 12, 2024 05:39
Show Gist options
  • Save hampusn/df5e091216f4698b9304 to your computer and use it in GitHub Desktop.
Save hampusn/df5e091216f4698b9304 to your computer and use it in GitHub Desktop.
A script which removes torrents from transmission when they are completed and stopped. Developed for Synology DiskStation as a cron job.
#!/bin/sh
# Called with the credentials for the rpc-username and rpc-password:
# ./cleanup-transmission-list.sh username password
# Exit early if user and pass is not passed as arguments
if [ "$1" == "" ] || [ "$2" == "" ]; then
exit 0;
fi
# Variables
USER=$1 # Param 1 (RPC Username)
PASS=$2 # Param 2 (RPC Password)
TRANSMISSION="/usr/local/transmission/bin/transmission-remote --auth "$USER":"$PASS
# Get a list of all current torrents ids.
TORRENTS=`$TRANSMISSION --list | sed -e '1d;$d;s/^ *//' | cut -s -d " " -f 1 | sed "s/[^0-9]//"`
# Loop through all torrents and remove them if they are completely finished
for TORRENT_ID in $TORRENTS
do
# Check if torrent is completed
IS_COMPLETED=`$TRANSMISSION --torrent $TORRENT_ID --info | grep "Percent Done: 100%"`
# Check if torrent is stopped
IS_STOPPED=`$TRANSMISSION --torrent $TORRENT_ID --info | grep "State: Stopped\|Finished\|Idle"`
if [ "$IS_COMPLETED" != "" ] && [ "$IS_STOPPED" != "" ]; then
$TRANSMISSION --torrent $TORRENT_ID --remove
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment