如何grep下载速度从wget输出? [英] How to grep download speed from wget output?
问题描述
我需要使用 wget
下载多个文件,并测量下载速度。
I need to download several files with wget
and measure download speed.
我用
wget -O /dev/null http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppy47.fs http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppyB47.fs
,输出为
--2010-10-11 18:56:00-- http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppy47.fs
Resolving ftp.bit.nl... 213.136.12.213, 2001:7b8:3:37:20e:cff:fe4d:69ac
Connecting to ftp.bit.nl|213.136.12.213|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1474560 (1.4M) [text/plain]
Saving to: `/dev/null'
100%[==============================================================>] 1,474,560 481K/s in 3.0s
2010-10-11 18:56:03 (481 KB/s) - `/dev/null' saved [1474560/1474560]
--2010-10-11 18:56:03-- http://ftp.bit.nl/pub/OpenBSD/4.7/i386/floppyB47.fs
Reusing existing connection to ftp.bit.nl:80.
HTTP request sent, awaiting response... 200 OK
Length: 1474560 (1.4M) [text/plain]
Saving to: `/dev/null'
100%[==============================================================>] 1,474,560 499K/s in 2.9s
2010-10-11 18:56:06 (499 KB/s) - `/dev/null' saved [1474560/1474560]
FINISHED --2010-10-11 18:56:06--
Downloaded: 2 files, 2.8M in 5.9s (490 KB/s)
我需要grep总下载速度, 490 KB / s
。
我如何做?
I need to grep the total download speed, that is, the string 490 KB/s
.
How do I do this?
可能需要说明我们实际只下载一个文件的情况,所以不会有 FINISHED
P.S. May need to account for the case that we will actually download only one file, so there won't be final output starting with FINISHED
推荐答案
更新,使用sed的grep风格版本:
Update, a grep-style version using sed:
wget ... 2>&1 | sed -n '$,$s/.*(\(.*\)).*/\1/p'
旧版本:
我想,将下载后的文件大小除以下载时间更容易。 ; - )
I thought, it's easier to divide the file size by the download time after the download. ;-)
(/usr/bin/time -p wget ... 2>&1 >/dev/null; ls -l newfile) | \
awk '
NR==1 {t=$2};
NR==4 {printf("rate=%f bytes/second\n", $5/t)}
'
第一个awk行在variabe t
中存储real xx.xx的已过实际时间。第二个awk行将文件大小( ls -l </ code>的第5列)除以时间并输出为速率。
The first awk line stores the elapsed real time of "real xx.xx" in variabe t
. The second awk line divides the file size (column 5 of ls -l
) by the time and outputs this as the rate.
这篇关于如何grep下载速度从wget输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!