Transmission auto-delete Quota Skript

Möchte man immer die aktuellsten frei zugänglichen Linux-Distributions Torrents herunterladen, um andere Nutzer durch die eigene Bandbreite zu unterstützen, wird irgendwann die Festplatte voll. Dieses Skript schafft Abhilfe.

#!/bin/bash
# transmission-quota.bash
#
# FIFO quota for transmission-daemon.
# This script forces a maximum size upon
# your transmission download directory
# by deleting the oldest torrent, until
# the quota is met again.
#
# Run regularily from cron:
# */5 * * * *     /home/torrent/transmission-quota.bash
#

# Where is your transmission download directory?
TR_DIR="/path/to/your/transmission/downloads"

# How big in bytes may the download directory grow?
TR_MAXBYTES=1879048192000

# Wheres your transmission-remote binary?
CLIPATH="/usr/bin/transmission-remote"

# Login:Password, if applicable
TR_UPASS="myUsername:myPassword"

# URL to Transmission RPC Interface (usually http://X:9091/transmission/rpc)
TR_URL="http://localhost:9091/transmission/rpc"

# # # No Configuration needed below here # # #

while [ "`du -sb ${TR_DIR} | awk '{print $1}'`" -gt "${TR_MAXBYTES}" ]; do
        CURRENT_SEEDING=`${CLIPATH} ${TR_URL} -n ${TR_UPASS} -l | awk '{ if ($2 == "100%") print $1 }' | sed 's/*$//'`
        OLDEST_TIMESTAMP=`date +%s`

        for torrent in ${CURRENT_SEEDING}
        do
                DATE_ADDED=`${CLIPATH} ${TR_URL} -n ${TR_UPASS} -t ${torrent} -i |grep "Date added:" | sed 's/Date added://g'`
                TIMESTAMP_ADDED=`date --date "${DATE_ADDED}" +%s`
                if [ "${TIMESTAMP_ADDED}" -lt "${OLDEST_TIMESTAMP}" ]; then
                        OLDEST_TIMESTAMP=${TIMESTAMP_ADDED}
                        OLDEST_ID=${torrent}
                fi
        done
        ${CLIPATH} ${TR_URL} -n ${TR_UPASS} -t ${OLDEST_ID} --remove-and-delete &> /dev/null
        DAYS_AGO=`echo $(( ( $(date +%s) - $OLDEST_TIMESTAMP ) / 3600 / 24 ))`
        echo deleted torrent id ${OLDEST_ID} from ${DAYS_AGO} days ago | logger -t transmission-quota
done

Schreibe einen Kommentar

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.