zvv

pt盒子seedbox自动删除任务的一些方法

最近刷累了,不想一直盯着换种,屌丝又买不起大硬盘的seedbox,论坛里的rss和autodl-irssi教程都不少,可是关于自动删种的倒是不多,是不是有盒子的都是500G+的?{:7_716:}从网上找了一下办法,总结一下,针对盒子的三种客户端,有三种方法。

1、transmission


#! /bin/bash
#====================================================================
# trans_cleanup.sh
#
# Copyright (c) 2011, WangYan <webmaster@wangyan.org>
# All rights reserved.
# Distributed under the GNU General Public License, version 3.0.
#
# Monitor disk space, If the Over, delete some files.
#
# See: http://wangyan.org/blog/trans_cleanup.html
#
# V0.2, since 2012-10-29
#====================================================================

# The transmission remote login username
USERNAME="demo"

# The transmission remote login password
PASSWORD="domo"

# The transmission download dir
DLDIR="/root/Downloads"

# The maximum allowed disk (%)
DISK_USED_MAX="95"

# Enable auto shutdown support (Disable=0, Enable=1)
ENABLE_AUTO_SHUTDOWN="0"

# Log path settings
LOG_PATH="/var/log/trans_cleanup.log"

# Date time format setting
DATA_TIME=$(date +"%y-%m-%d %H:%M:%S")

#====================================================================

dist_check()
{
    DISK_USED=`df -h $DLDIR | grep -v Mounted | awk '{print $5}' | cut -d '%' -f 1`
    DISK_OVER=`awk 'BEGIN{print('$DISK_USED'>'$DISK_USED_MAX')}'`
}

dist_check

if [ "$DISK_OVER" = "1" ];then
        for i in `transmission-remote --auth $USERNAME:$PASSWORD -l | grep 100% | grep Done | awk '{print $1}' | grep -v ID`
        do
                [ "$i" -gt "0" ] && echo -n "$DATA_TIME [Done] " >> $LOG_PATH
                transmission-remote --auth $USERNAME:$PASSWORD -t $i --remove-and-delete >> $LOG_PATH 2>&1
                [ "$i" -gt "0" ] && sleep 10 && dist_check
                [ "$DISK_OVER" = "0" ] && break
        done
fi

if [ "$DISK_OVER" = "1" ];then
        for ii in `transmission-remote --auth $USERNAME:$PASSWORD -l | grep Stopped | awk '{print $1}' | grep -v ID`
        do
                [ "$ii" -gt "0" ] && echo -n "$DATA_TIME [Stopped] " >> $LOG_PATH
                transmission-remote --auth $USERNAME:$PASSWORD -t $ii --remove-and-delete >> $LOG_PATH 2>&1
                [ "$ii" -gt "0" ] && sleep 10 && dist_check
                [ "$DISK_OVER" = "0" ] && break
        done
fi

if [ "$DISK_OVER" = "1" ];then
        for iii in `transmission-remote --auth $USERNAME:$PASSWORD -l | grep -v Sum | awk '{print $1}' | grep -v ID`
        do
                [ "$iii" -gt "0" ] && echo -n "$DATA_TIME [Up or Down] " >> $LOG_PATH
                transmission-remote --auth $USERNAME:$PASSWORD -t $iii --remove-and-delete >> $LOG_PATH 2>&1
                [ "$iii" -gt "0" ] && sleep 10 && dist_check
                [ "$DISK_OVER" = "0" ] && break
        done
fi

if [ "$DISK_OVER" = "1" ];then
        rm -rf $DLDIR/*
fi

if [ "$ENABLE_AUTO_SHUTDOWN" = "1" ];then
        SHUTDOWN=1
        for STATUS in `transmission-remote --auth $USERNAME:$PASSWORD -l | awk '{print $9}'`
        do
                if [[ "$STATUS" = "Up" || "$STATUS" = "Uploading" ]];then
                        SHUTDOWN=0
                fi
        done
        TASK_TOTAL=`transmission-remote --auth $USERNAME:$PASSWORD -l | grep -Ev '(ID|Sum)' | wc -l`
        if [ "$TASK_TOTAL" -gt "0" ] && [ "$SHUTDOWN" -eq "1" ];then
                echo -n "$DATA_TIME " >> $LOG_PATH
                shutdown now >> $LOG_PATH 2>&1
        fi
fi

脚本配置:
1)登录用户名,默认是demo

USERNAME="demo"

2)登录密码,默认是demo

PASSWORD="domo"

3)transmission下载目录,默认在/root/Downloads

DLDIR=/root/Downloads

4)磁盘最大使用阀值,默认95%

DISK_USED_MAX="95"

5)日志存放路径,默认在/var/log/trans_cleanup.log

LOG_PATH="/var/log/trans_cleanup.log"

6)日志日期格式,一般不需要改。

DATA_TIME=$(date +"%y-%m-%d %H:%M:%S")

将配置好的脚本保存在/root/trans_cleanup.sh,然后设置计划任务:

crontab -e
*/5 * * * * /bin/bash /root/trans_cleanup.sh

删除顺序说明:

首先逐个删除已经下载完的任务,一旦满足条件则停止删除。
接着逐个删除已经暂停的任务,一旦满足条件则停止删除。
最后按顺序删除正在下载的任务(相当于删除全部任务),直到满足条件。
如果还是未能满足条件,则动用"rm -rf"强制删除下载目录内的所有文件。


2、Deluge
注意:deluge的脚本不适用于只安装deluged和deluge-web的盒子!

from deluge.ui.client import client
from twisted.internet import reactor
from twisted.internet import defer
from deluge.log import setupLogger
import json
import time

MAX_WAIT_TIME = 10
MIN_UPLOAD_SPEED = 50 * 1024
db = {}

def donothing(status):
  return status

def on_get_torrents_status(torrents_status):
        global db
        global MAX_WAIT_TIME
        global MIN_UPLOAD_SPEED
        tlist = []
        for torrent_id in torrents_status:
            torrent_info = torrents_status[torrent_id]            
            if torrent_info['state'] == 'Seeding':
                if not db.has_key(torrent_id):
                    db[torrent_id] = 0
                if torrent_info['upload_payload_rate'] < MIN_UPLOAD_SPEED:
                    db[torrent_id] = db[torrent_id] + 1
                else:
                    db[torrent_id] = 0
                if db[torrent_id] > MAX_WAIT_TIME:
                    db.pop(torrent_id)
                    tlist.append(client.core.remove_torrent(torrent_id, True).addCallback(donothing))
            if  torrent_info['state'] == 'Queued':
                    tlist.append(client.core.remove_torrent(torrent_id, True).addCallback(donothing))
            if  torrent_info['state'] == 'Error':
                    tlist.append(client.core.remove_torrent(torrent_id, True).addCallback(donothing))
        if len(tlist) > 0:
                defer.DeferredList(tlist).addCallback(Cleanup)
                time.sleep(3)
        else:
                Cleanup(True)

def Cleanup(status):
        global db
        client.disconnect()
        try:
          f = open('autoclean.db', 'w')
          f.write(json.dumps(db))
          f.close()
        except:
          db = {}
        reactor.stop()

def on_connect_success(result):        
    client.core.get_torrents_status(None,
        ['id', 'name', 'state', 'ratio', 'progress', 'upload_payload_rate', 'total_seeds', 'total_peers']).addCallback(on_get_torrents_status)

def on_connect_fail(result):
    print "Connection failed!"
    print "result:", result

setupLogger()
try:
  f = open('autoclean.db', 'r')
  db = json.loads(f.readlines()[0])
  f.close()
except:
  db = {}   
d = client.connect()
d.addCallback(on_connect_success)
d.addErrback(on_connect_fail)
reactor.run()
复制代码

脚本配置:
1)X分钟不活动即删种,默认为10

MAX_WAIT_TIME = 10

2)代表上传速度小于X kb就认为种子不活动,默认为50

MIN_UPLOAD_SPEED = 50 * 1024

将配置好的脚本保存为/root/autoclean.py,然后设置计划任务:

crontab -e
*/1 * * * * /usr/bin/python /root/autoclean.py

3、rtorrent/rutorrent
对于rutorrent就简单许多,因为rutorrent自带分享率控制插件,可以手动设置最低分享率、最高分享率、最大上传量和做种时间。



总结一下,三种方法各有优缺点。transmission的脚本保证了磁盘一直不会满,但是种子速度无法保证;deluge的脚本可以自动删除低速种子,但是如果种子全在Downloading是不会删种的;rutorrent的分享率控制插件可以保证一些有H&R的站对于分享率和做种时间的要求,对于种子速度和磁盘空间是无法监控的。

我对于Linux不是很熟悉,这些脚本其实都还有可以优化的地方,不知道有木有大神指导指导{:7_725:}



transmission脚本来源:http://wangyan.org/blog/trans_cleanup.html
deluge脚本来源:http://hdchina.org/forums.php?action=viewtopic&topicid=83254

 

via.http://www.gebi1.com/thread-193128-1-1.html

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »

因本文不是用Markdown格式的编辑器书写的,转换的页面可能不符合AMP标准。