Solved

Average speed from curl

Posted on 2013-05-10
4
501 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 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

776 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