Skip to content

Instantly share code, notes, and snippets.

@morganp
Last active June 12, 2024 05:34
Show Gist options
  • Save morganp/044b80a80ff3e956acfca4f46451608b to your computer and use it in GitHub Desktop.
Save morganp/044b80a80ff3e956acfca4f46451608b to your computer and use it in GitHub Desktop.
Script Transmission to remove torrent, and move data after specified time
#!/usr/bin/env bash
# Remove torrents from Transmission after a set number of days.
# Life cylce is: Incomplete -> Completed & Seeding -> Completed & removed for client
# In part based on:
# https://community.wd.com/t/guide-auto-removal-of-downloads-from-transmission-2-82/93156
SERVER='192.168.0.29'
DAYS=21
# Turn Days into Seconds
REMOVE_AFTER=`expr $DAYS \* 24 \* 60 \* 60`
REMOVED_FOLDER=/Users/lounge/Downloads/Completed/
# transmission-remote SERVER_IP
# -t --torrent all | active | id | torrent-hash
# Set the current torrent(s) for use by subsequent options. The literal all will apply following requests to
# all torrents; the literal active will apply following requests to recently-active torrents; and specific
# torrents can be chosen by id or hash. To set more than one current torrent, join their ids together in a
# list, such as "-t2,4,6-8" to operate on the torrents whose IDs are 2, 4, 6, 7, and 8.
#-i --info
# Show details of the current torrent(s)
#
# -if --info-files
# List the specified torrent's files
#
# -ip --info-peers
# List the specified torrent's peers
#
# -ic --info-pieces
# List the specified torrent's pieces
#
# -it --info-trackers
# List the specified torrent's trackers
#
# -si --session-info
# List session information from the server
#
# -st --session-stats
# List statistical information from the server
#
# -l --list
# List all torrents
#transmission-remote 192.168.0.29 -t all -i | grep 'Seeding Time'
TORRENTIDS=`transmission-remote $SERVER -l | grep 100% | awk '{print $1}' | xargs -n 1 -I %`
for TORRENTID in $TORRENTIDS
do
TORRENT_SEED_SECONDS=`transmission-remote $SERVER -t $TORRENTID -i | grep 'Seeding Time' | sed 's/Seeding.*(\(.*\) seconds)/\1/'`
if [ "$TORRENT_SEED_SECONDS" -gt "$REMOVE_AFTER" ] ; then
echo "Times up"
# Move Data
transmission-remote $SERVER -t $TORRENTID --move $REMOVED_FOLDER
# Remove Torrent
transmission-remote $SERVER -t $TORRENTID --remove
fi
done
@morganp
Copy link
Author

morganp commented Sep 4, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment