Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Average speed from curl

Posted on 2013-05-10
4
Medium Priority
?
657 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
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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will giveā€¦
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

886 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