多个种子的传输关闭脚本?

Khu*_*lam 4 command-line bash shutdown scripts transmission

我已经写了一个关闭脚本进行传输。在 torrent 下载完成后,传输会调用脚本。该脚本在我的机器上完美运行(Ubuntu 11.04 和 12.04)。

#!/bin/bash
sleep 300s

# default display on current host
DISPLAY=:0.0

# find out if monitor is on. Default timeout can be configured from screensaver/Power configuration.

STATUS=`xset -display $DISPLAY -q | grep 'Monitor'`
echo $STATUS

if [ "$STATUS" == "  Monitor is On" ]

###  Then check if  its still downloading a torrent. Couldn't figure out how.(May be) by monitoring network downstream activity? 

then

    notify-send "Downloads Complete" "Exiting  transmisssion now"
    pkill transmission

else
    notify-send "Downloads Complete" "Shutting Down Computer"
    dbus-send --session --type=method_call --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.RequestShutdown

fi

exit 0
Run Code Online (Sandbox Code Playgroud)

问题是当我下载多个文件时,当第一个文件完成时,传输会执行脚本。我想这样做,但在所有下载完成后。

如果它仍在下载另一个 torrent,我想进行第二次检查(在监视器检查之后)。

有没有办法做到这一点?

小智 5

此信息不会通过环境变量传递给脚本,因此您需要查询传输的 RPC 接口。这有时是由客户端库完成的——例如,Python 脚本可以使用python transmissionrpchttp://www.transmissionbt.com/resources/ 上还列出了其他类似的接口。

这是一种使用传输远程计算非空闲下载次数的快速方法:

transmission-remote yourhost:yourport -tall --info | grep "^  State:" | grep "Down" | wc --lines
Run Code Online (Sandbox Code Playgroud)

如果你也想包括空闲下载,你可以试试这个:

transmission-remote yourhost:yourport -l | grep -v -e " 100% " -e "^Sum" -e "^ID" -e " Stopped " | wc --lines
Run Code Online (Sandbox Code Playgroud)

其中“^ID”和“^Sum”去除页眉和页脚;“100%”条带完成种子;和“停止”去除未完成但已暂停的种子。这种方法不是万无一失的——例如,名为“100% Stopped”的 torrent 会破坏它。