是否可以抓取wget的最后一行?

发布于 2024-12-07 13:49:16 字数 485 浏览 0 评论 0原文

$ wget --output-document=/dev/null http://website.com/file.jpg

Resolving speedtest.sea01.softlayer.com... 67.228.112.250
Connecting to speedtest.sea01.softlayer.com|67.228.112.250|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1986284 (1.9M) [image/jpeg]
Saving to: `/dev/null'

2011-10-02 22:38:04 (337 KB/s) - `/dev/null' saved [1986284/1986284]

上面一切正常,但我想知道如何将最后一行存储在变量中或通过 GREP -> 传递它/((.+))/

(我正在尝试解析平均 KB/s)

$ wget --output-document=/dev/null http://website.com/file.jpg

Resolving speedtest.sea01.softlayer.com... 67.228.112.250
Connecting to speedtest.sea01.softlayer.com|67.228.112.250|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1986284 (1.9M) [image/jpeg]
Saving to: `/dev/null'

2011-10-02 22:38:04 (337 KB/s) - `/dev/null' saved [1986284/1986284]

Everything works above, but I would like to know how to store the last line in a variable OR pass it through GREP -> /((.+))/

(I'm trying to parse for the average KB/s)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光瘦了 2024-12-14 13:49:16

您可以重定向命令的输出。例如:

$ wget --output-document=/dev/null http://website.com/file.jpg 2>&1 | tee /tmp/somefile
$ tail -n 1 /tmp/somefile

You can redirect the output of the command. For example:

$ wget --output-document=/dev/null http://website.com/file.jpg 2>&1 | tee /tmp/somefile
$ tail -n 1 /tmp/somefile
一萌ing 2024-12-14 13:49:16

如果您安装了 apache,则可以使用 Apache HTTP 服务器基准测试工具:

ab -n1 http://website.com/file.jpg | grep -F 'Transfer rate:'

您会得到如下输出:

Transfer rate:          1722.38 [Kbytes/sec] received

If you have apache installed, you can use Apache HTTP server benchmarking tool:

ab -n1 http://website.com/file.jpg | grep -F 'Transfer rate:'

you get output like:

Transfer rate:          1722.38 [Kbytes/sec] received
旧人 2024-12-14 13:49:16
wget -O /dev/null  http://website.com/file.jpg 2>&1 |
sed -n '\%/dev/null%!d;s/.*(//;s/).*//p'

在我的系统上,最终的输出行是空的,否则 sed 寻址会更简单。这是在 Ubuntu 上开箱即用的;如果您的 sed 不同,您可能需要稍微调整脚本。

(我首先尝试使用 grep -o '(.*)',但在 wget 的输出中前面的括号中还有其他文本。)

wget -O /dev/null  http://website.com/file.jpg 2>&1 |
sed -n '\%/dev/null%!d;s/.*(//;s/).*//p'

On my system, the final output line is empty, otherwise the sed addressing would be simpler. This is on Ubuntu out of the box; if your sed is different, you may need to adapt the script slightly.

(I tried with grep -o '(.*)' at first, but there is other text in parentheses earlier in the output from wget.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文