Bash 清除腐败的洪流

Bash 清除腐败的洪流,bash,debian,Bash,Debian,我不记得在哪里找到的,但我有一个脚本,一旦种子植入完成,它将从传输中删除种子 我想添加一个部分,也删除损坏的种子。已损坏的Torrent将具有以下行: 错误:未找到任何数据!确保驱动器已连接或使用“设置位置”。要重新下载,请删除torrent并重新添加。 这是我的剧本: #!/bin/sh #transmission-remote --auth=user:pass --torrent 1 --info #transmission-remote --auth=user:pass --list

我不记得在哪里找到的,但我有一个脚本,一旦种子植入完成,它将从传输中删除种子

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

错误:未找到任何数据!确保驱动器已连接或使用“设置位置”。要重新下载,请删除torrent并重新添加。

这是我的剧本:

#!/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”可以解决我的问题,但这会删除所有未损坏的Torrent

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

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


Eddie

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

更改行:

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

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

请参阅以获得良好的描述

此外,如果,则应将以下内容更改为

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


嗨,布朗斯特德,谢谢你的回复,我想你让我走对了方向。所以,不是所有的洪流都说腐败,而是说没有腐败。Torrent#16未损坏。忽略。Torrent#18未损坏。忽略。Torrent#19*未损坏。忽略。但是,我确实注意到损坏的那个在数字后面有一个星号。Torrent 19应该被破坏。
if [ "$DL_STOPPED" = !"" ]; then
if [ "$DL_STOPPED" != "" ]; then