wget 打印错误,但没有其他内容

wget 打印错误,但没有其他内容

为什么我会有 wget 打印错误,但没有其他错误?

在默认行为中,它会显示进度条和许多内容。

在 --no-verbose 版本中仍然会为每个下载的文件打印一行,这是我不想要的。

--quiet 选项使其完全安静,即使出现错误,它也不会打印任何内容。

是否存在一种模式,只打印错误,而不打印其他内容?

答案1

这个问题有很多很好的答案,一定要看看,但我所做的是这样的:

wget [wget options] 2>&1 | grep -i "failed\|error"

答案2

使用 curl,没有必要猜测每个错误会是什么样子。

[wizard@laptop ~] curl -s -S http://www.google.coccm/ > /dev/null && echo "TRUE"
curl: (6) Couldn't resolve host 'www.google.coccm'
[wizard@laptop ~]$ curl -s -S http://www.google.com/ > /dev/null && echo "TRUE"
TRUE

-s/--静音

Silent mode. Don’t show progress meter or error messages. Makes Curl mute.

-S/--显示错误

When used with -s it makes curl show error message if it fails.

如果由于某种原因您需要在 stdout 上使用 stderr。

curl -s -S http://www.google.coccm/  2>&1 1> /dev/null

答案3

我没有看到这个选项。您需要知道错误是什么,还是只需要知道是否发生了错误?如果您恰好只需要知道是否有错误,则可以使用退出状态。

if ! wget -o /dev/null www.google.com/flasfsdfsdf; then
    echo 'Oops!'
fi

或者可能:

if ! wget -o logfile www.google.com/flasfsdfsdf; then
    cat logfile
fi

如果您想要更高级一点的话,您可以将 cat 更改为 grep 命令...

答案4

将标准输出重定向到/dev/null,但将错误输出保留在您选择的 shell 中。

在 Bash 中这将是:

wget [wget options] > /dev/null

编辑:所以wget行为不当。如果所有错误都包含单词“error”,则可以通过管道传输到grep

wget [wget options] 2>&1 | grep -i "error"

相关内容