wget 打印错误,但没有别的

Pab*_*blo 34 wget

我怎么能有 wget 打印错误,但没有其他问题?

在默认行为中,它显示一个进度条和很多东西。

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

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

有没有一种模式可以打印错误,但没有别的?

Pab*_*blo 22

这个问题有很好的答案,一定要检查出来,但我所做的是:

wget [wget options] 2>&1 | grep -i "failed\|error"
Run Code Online (Sandbox Code Playgroud)


rec*_*bot 18

使用 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
Run Code Online (Sandbox Code Playgroud)

-s/--沉默

Silent mode. Don’t show progress meter or error messages. Makes Curl mute.
Run Code Online (Sandbox Code Playgroud)

-S/--show-error

When used with -s it makes curl show error message if it fails.
Run Code Online (Sandbox Code Playgroud)

如果您出于某种原因需要 stdout 上的 stderr。

curl -s -S http://www.google.coccm/  2>&1 1> /dev/null
Run Code Online (Sandbox Code Playgroud)


Kyl*_*ndt 5

我没有看到这样的选择。您是否需要知道错误是什么,或者只是知道错误是否发生?如果您只是需要知道是否有错误,则可以使用退出状态。

if ! wget -o /dev/null www.google.com/flasfsdfsdf; then
    echo 'Oops!'
fi
Run Code Online (Sandbox Code Playgroud)

或者可能:

if ! wget -o logfile www.google.com/flasfsdfsdf; then
    cat logfile
fi
Run Code Online (Sandbox Code Playgroud)

如果你想变得更奇特,你可以将 cat 更改为 grep 命令......

  • 更简单的方法: wget -o logfile <url> || 猫日志文件 (3认同)