之前写过一个CentOS下的刷PT流量教程,但是我一直不喜欢CentOS,尤其是那个内核管理。折腾了一下,终于搞定了Debian和Ubuntu下的方法。
!!!只适用于Debian9和Ubuntu16以上的系统!!!
一、安装Transmission
1 2 |
apt-get update apt-get install transmission-daemon -y |
修改配置需要先停止运行:
1 2 |
/etc/init.d/transmission-daemon stop vi /var/lib/transmission-daemon/info/settings.json |
需要修改其中的部分内容:
1 2 3 4 5 |
rpc-username 帐号 rpc-password 密码 "rpc-authentication-required": true "rpc-whitelist-enabled": false "preallocation": 0 |
启动:
1 |
/etc/init.d/transmission-daemon start |
通过http://ip:9091,可以访问transmission的webui。
二、安装FlexGet
逐条执行(切记):
1 |
apt-get install -y python-pip python-setuptools nano |
1 |
pip install --upgrade pip |
1 |
pip2 install flexget |
配置FlexGet:
1 2 |
mkdir /root/.flexget nano /root/.flexget/config.yml |
只能用nano,vi和vim大概不支持带.的目录。
FlexGet配置文件示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
tasks: mt: rss: https://tp.m-team.cc/torrentrss.php?https=1&rows=10&linktype=dl&passkey=xxxxxxxxxxxxxx accept_all: yes content_size: min: 256 max: 4000 download: /var/lib/transmission-daemon/torrents transmission: host: 127.0.0.1 port: 9091 username: username password: password ttg: rss: https://totheglory.im/putrss.php?par=xxxxxxx&ssl=yes accept_all: yes content_size: min: 256 max: 4000 download: /var/lib/transmission-daemon/torrents transmission: host: 127.0.0.1 port: 9091 username: username password: password |
以上内容表示,只下载文件大小在256MB和4000MB之间的种子,用户名和密码为之前配置的transmission的。rss为pt网站订阅的rss地址。一般选择所有的就行了,TTG等网站需要注意最好不要覆盖那些带H&R的内容(剧集)。
多个任务,在后面添加即可。
因为没有这个种子文件下载目录,需要先创建:
1 |
mkdir /var/lib/transmission-daemon/torrents |
FlexGet配合transmission还需要插件支持:
1 |
pip2 install transmissionrpc |
FlexGet简单命令:
1 2 |
flexget check : 用于检查 config.yml 配置文件是否有格式错误。 flexget execute : 手动开始一次 RSS 下载,就等于正式 RSS 了一次。 |
可以执行一次flexget check,一般是没有问题的。
添加自动任务:
1 |
crontab -e |
在其中添加:
1 |
*/5 * * * * /usr/local/bin/flexget -c /root/.flexget/config.yml execute |
表示每5分钟更新一次RSS。
三、自动删除种子文件
先创建Shell文件:
1 |
vi trans_cleanup.sh |
其中内容为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#! /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="username" # The transmission remote login password PASSWORD="password" # The transmission download dir DLDIR="/var/lib/transmission-daemon/downloads" # The maximum allowed disk (%) DISK_USED_MAX="90" # 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 |
自行修改其中的username和password,以及DISK_USED_MAX=”90″,这个数值表示最大可占用的硬盘空间,超过以后就会自动删除pt种子。不要设置太大,谨防下载速度太快爆硬盘,会导致服务器无法连接。
创建自动任务,在crontab里添加:
1 |
*/1 * * * * /bin/bash /root/trans_cleanup.sh |
每分钟检查一次硬盘空间占用。
注意:如果硬盘空间太小,可能会导致每个种子的分享率不高,按需要调节每个种子文件大小限制,或者减少添加的task。
- 本文固定链接: https://www.ljchen.com/archives/963
- 转载请注明: ljchen 于 三言两语 发表
博主,你的第三部删除种子,不会VI编辑怎么办?能用winSCP吗?win的话怎么操作?
用winscp也是可以的,在Windows里面先写好这个trans_clean.sh文件,注意文件的格式,在notepad++的右下角,可以把文件转换为Unix格式,再用winscp上传到vps里面。你也可以在VPS里面使用nano trans_clean.sh来编辑这个文件,把我的脚本内容复制进去以后,Ctrl+O保存,Ctrl+X退出,即可。
博主你好,我按你的教程搭建成功了,可是今天爆盘了,我设置了80%,现在100%了,不会自己删除?
自动任务我添加在/tmp/crontab.WR7EQn/crontab这个路径
自动任务
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use ‘*’ in these fields (for ‘any’).#
# Notice that tasks will be started based on the cron’s system
# daemon’s notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
*/5 * * * * /usr/local/bin/flexget -c /root/.flexget/config.yml execute
*/1 * * * * /bin/bash /root/trans_cleanup.sh
/var/lib/transmission-daemon/info/settings.json
trans_cleanup.sh
这两个文件中的下载目录是一样的吗?应该都是同一个目录才对,我的是/var/lib/transmission-daemon/downloads。
我看你在论坛里面说要修改下载目录,你确认一下是不是忘了改了。
我后来重装系统的时候改回一个盘了,下载路径都按你的,没改动!
你手动执行一下这个脚本,是什么效果?bash /root/trans_cleanup.sh
root@sd-94343:/home/kaysin# bash /root/trans_cleanup.sh
bash: /root/trans_cleanup.sh: No such file or directory
你的root目录下面没有这个脚本文件啊
。。。。。可是我能打开着文件?我是用nano来编辑的,输入完之后就ctrl+O,ctrl+X,这是保存了么?= =
位置错了或者文件名字错了吧
用winSCP看了下,文件位置错了,创建在home文件夹里面,我用了5O来做,online好像只能设置用户权限,SSH进去再用代码获取管理,不能直接ROOT!我重新在/里创建了trans_cleanup.sh,看看能不能自动删除!
在home也没关系啊,把crontab里的定时任务指定的路径改了就可以了。