Skip to content

Instantly share code, notes, and snippets.

@JoooostB
Created January 25, 2019 20:53
Show Gist options
  • Save JoooostB/41122e9451180d839905a25fa12d0c88 to your computer and use it in GitHub Desktop.
Save JoooostB/41122e9451180d839905a25fa12d0c88 to your computer and use it in GitHub Desktop.
Script to automatically remove torrents and delete local data from your Transmission client after seeding for x amount of days (15 by default).
#!/bin/bash
# Enter your username and password for your Transmission instance
USER=username
PASSWD=passw0rd123
# Obtain index ids of completed torrents.
torrent_ids=$(transmission-remote -n $USER:$PASSWD -l\
| awk '$5=="Done"{print $1}')
for index in $torrent_ids; do
# Get creation date from torrent details.
created=$(transmission-remote -n $USER:$PASSWD -t $index -i\
| grep "Date added:"\
| cut -d: -f2-\
| sed 's/^ *//')
echo -e "Torrent $index:\n\tcreated:$created"
# Calculate torrent's age.
# Convert dates to timestap so they can be substracted.
now_ts=$(date +%s)
torrent_ts=$(date +%s -d "$created")
# Substract timestamps and get days difference.
secs_in_day=86400
age=`echo \($now_ts - $torrent_ts\) / $secs_in_day| bc`
echo -e "\tthat's $age days old."
# If it's older than 15 days old, delete it.
if [ $age -ge 15 ]; then
echo -e "\t *** Removing ***"
echo -e "\ttransmission-remote -n $USER:$PASSWD -t $index --remove-and-delete"
transmission-remote -n $USER:$PASSWD -t $index --remove-and-delete
else
echo -e "\tKept."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment