Skip to content

Instantly share code, notes, and snippets.

@magarcia
Created November 2, 2015 19:31
Show Gist options
  • Save magarcia/ea5467e0724bfc11cac0 to your computer and use it in GitHub Desktop.
Save magarcia/ea5467e0724bfc11cac0 to your computer and use it in GitHub Desktop.
Clean finished torrents and remove files if has hard link
#!/usr/bin/env bash
function join { local IFS="$1"; shift; echo "$*"; }
REMOTE="transmission-remote --auth osmc:osmc"
DATA=`$REMOTE --list | grep Finished | awk '{print $1'}`
for i in $DATA
do
FILES=`$REMOTE -t $i -f | grep "^ " | grep -v "#" | awk '{ print substr($0, index($0,$7)) }' | uniq | tr " " "|"`
remove=false
for f in $FILES
do
DIR=`echo "/data/Downloads/$f" | tr "|" " "`
if [ "$(stat -c %h -- "$DIR")" -gt 1 ]; then
remove=true
fi
done
if [ "$remove" == true ]; then
$REMOTE -t $i --remove-and-delete
echo [`date -u`] Remove `$REMOTE -t $i -i | grep Name | awk '{print $2}'` >> /var/log/torrent-cleaner.log
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment