Is it possible to grab the last line of wget?
$ 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... connec开发者_StackOverflow中文版ted.
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)
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
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
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
.)
精彩评论