【问题标题】:Remove corrupt torrents删除损坏的种子
【发布时间】:2014-08-21 15:24:05
【问题描述】:

我不记得在哪里找到的,但我有一个脚本,一旦种子完成播种,就会从传输中删除种子。

我想添加一个部分来删除损坏的种子。损坏的种子将具有以下行:

错误:未找到数据!确保您的驱动器已连接或使用“设置位置”。要重新下载,请移除种子文件并重新添加。

这是我的脚本:

#!/bin/sh

#transmission-remote --auth=user:pass --torrent 1 --info
#transmission-remote --auth=user:pass --list

TRUSER='user'
TRPASS='pass'
TORRENTLIST=`transmission-remote --auth=$TRUSER:$TRPASS --list | sed -e '1d;$d;s/^ *//' | cut --only-delimited --delimiter=' ' --fields=1`


for TORRENTID in $TORRENTLIST
do
echo "* * * * * Operations on torrent ID $TORRENTID starting. * * * * *"
DL_COMPLETED=`transmission-remote --auth=$TRUSER:$TRPASS --torrent $TORRENTID --info | grep "State: Finished"`
if [ "$DL_COMPLETED" != "" ]; then
echo "Torrent #$TORRENTID is completed."
echo "Removing torrent from list."
transmission-remote --auth=$TRUSER:$TRPASS --torrent $TORRENTID --remove-and-delete
else
echo "Torrent #$TORRENTID is not completed. Ignoring."
fi
echo "* * * * * Operations on torrent ID $TORRENTID completed. * * * * *"
done


for TORRENTID in $TORRENTLIST
do
echo "* * * * * Operations on torrent ID $TORRENTID starting. * * * * *"
DL_STOPPED='transmission-remote --auth=$TRUSER:$TRPASS --torrent $TORRENTID --info | grep -o "Error: No data found"'
if [ "$DL_STOPPED" = !"" ]; then
echo "Torrent #$TORRENTID is corrupted."
echo "Removing torrent from list."
transmission-remote --auth=$TRUSER:$TRPASS --torrent $TORRENTID --remove-and-delete
else
echo "Torrent #$TORRENTID is not corrupted. Ignoring."
fi
echo "* * * * * Operations on torrent ID $TORRENTID completed. * * * * *"
done

我认为在 grep 之后添加“-o”可以解决我的问题,但是这会删除所有未损坏的种子。

如何让此脚本删除已完成的播种和损坏的种子?

这是我第一次发帖,所以我希望我做得对。

艾迪

【问题讨论】:

    标签: bash debian


    【解决方案1】:

    问题是您使用的是单引号而不是反引号。

    换行:

    DL_STOPPED='transmission-remote --auth=$TRUSER:$TRPASS --torrent $TORRENTID --info | grep -o "Error: No data found"'
    

    到:

    DL_STOPPED=`transmission-remote --auth=$TRUSER:$TRPASS --torrent $TORRENTID --info | grep -o "Error: No data found"`
    

    单引号表示 bash 中的字符串,而反引号在子 shell 中执行字符串。无论如何,我认为使用 $( ...) 更好,因为这种表示法允许嵌套。

    请参阅https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html 了解详细说明

    另外,您应该将if从:

    if [ "$DL_STOPPED" = !"" ]; then
    

    到:

    if [ "$DL_STOPPED" != "" ]; then 
    

    【讨论】:

    • 您好,bronsted,感谢您的回复,我认为您的方向是正确的。因此,不是所有的种子都说已损坏,而是都说未损坏。 Torrent #16 未损坏。无视。 Torrent #18 未损坏。无视。 Torrent #19* 未损坏。无视。但是,我确实注意到损坏的那个数字后面有一个星号。 Torrent 19 应该被破坏。
    猜你喜欢
    • 1970-01-01
    • 2013-06-04
    • 2016-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多