Solved

Average speed from curl

Posted on 2013-05-10
4
471 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
  • 2
  • 2
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Perfect, thanks very much
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Utilizing an array to gracefully append to a list of EmailAddresses
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now