Skip to content

Instantly share code, notes, and snippets.

@noah
Created June 13, 2017 03:50
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 noah/dcc5cc89d215da71d418698033f858ea to your computer and use it in GitHub Desktop.
Save noah/dcc5cc89d215da71d418698033f858ea to your computer and use it in GitHub Desktop.
Cron task to delete torrents from rtorrent after 48 hours of seeding.
#!/bin/sh
# Close torrents in rtorrent after x hours of seeding
# dependencies: libxmlrpc-core-c3-dev, bc, nginx
# https://github.com/mdevaev/emonoda/wiki/rTorrent-XMLRPC-Reference
# http://elektito.com/2016/02/10/rtorrent-xmlrpc/
x=48
SERVER=localhost:8000
now=$(date +%s)
xmlrpc $SERVER download_list "" complete | while read line; do
l="$(echo "$line" | grep Index)"
if [ -n "$l" ]; then
h="$(echo "$l"|cut -d' ' -f5 | tr -d "'" )"
t=$(xmlrpc $SERVER d.timestamp.finished "$h"\
|grep integer\
|cut -d ' ' -f3)
diff="$(echo "($now-$t)/3600"| bc)"
if [ $diff -gt $x ]; then
echo $h
xmlrpc $SERVER d.close $h
xmlrpc $SERVER d.erase $h
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment