Solved

Average speed from curl

Posted on 2013-05-10
4
569 Views
Last Modified: 2013-05-10
Hi,

Using curl, I would like to extract the average speed field into a variable.
However, I can't find a way to both suppress the progress info AND show the final stats.
So I guess we're down to tailing the very last progress line (^M delim) and pulling out the field.

e.g.
curl -o /dev/null  http://download.thinkbroadband.com/1MB.zip

Gives
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1024k  100 1024k    0     0   297k      0  0:00:03  0:00:03 --:--:--  304k

I need 297k extracted.

Any help would be appreciated.

BT
0
Comment
Question by:brothertom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 39155321
curl  writes to stderr!

AVGSPEED=$(curl -o /dev/null  http://download.thinkbroadband.com/1MB.zip 2>&1 | awk '{A=$7} END {print A}') 

Open in new window

0
 

Author Comment

by:brothertom
ID: 39155388
This results in 0 value.
The reason is curl uses carriage return to display the stats.

So, the stderr output is actually


  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0^M 12 1024k   12  127k    0     0   278k      0  0:00:03 --:--:--  0:00:03  343k^M 56 1024k   56  574k    0     0   392k      0  0:00:02  0:00:01  0:00:01  417k^M 99 1024k   99 1020k    0     0   414k      0  0:00:02  0:00:02 --:--:--  429k^M100 1024k  100 1024k    0     0   413k      0  0:00:02  0:00:02 --:--:--  428k

So the processing needs to strip all lines before ^M100 (i.e. 100%) and process the remainder.  That is the problem I'm having doing.

Thanks
BT
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39155429
Ok, you're right. My test download was too small. Try this:

AVGSPEED=$(curl -o /dev/null  http://download.thinkbroadband.com/1MB.zip 2>&1 | awk 'BEGIN {RS="\r"}{A=$7} END {print A}')

Open in new window

0
 

Author Closing Comment

by:brothertom
ID: 39155480
Perfect, thanks very much
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question