Solved

Average speed from curl

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AWS Central Authentication 1 87
ftp to port 21 4 54
Bash script - Exit out of choice loop 2 44
Moving from Mcrypt to OpenSSL 18 46
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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…

831 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