Pages

Thursday, 20 September 2012

rTorrent 自动限速脚本


rTorrent 下载 PT 种子很容易就可以满速,虽然可以通过 qos-script 来降低 p2p 的优先级,但对于 PC 上的在线视频等应用效果不够理想,通过以下脚本可以在指定 IP 的 PC 上线后自动对 rTorrent 降速。
#!/bin/sh
# Automatic tune rTorrent download speed limit
dl="150"
for ip in cat /proc/net/arp | tail +2 | awk '{print $1}'
do
        if [ $ip = "192.168.1.101" -o $ip = "192.168.1.102" ]; then
                dl="50"
        fi
done
screen -r rtorrent -X eval "stuff ^Xthrottle.global_down.max_rate.set_kb=$dl^M"
把这个脚本保存为 /usr/local/bin/p2pman,在 /etc/crontab/root 下加入如下一行
*/5 * * * * /usr/local/bin/p2pman > /dev/null