4

Notice that this question is distinctly different from How do I get cURL to not show the progress bar? though a valid answer to this question would likely suffice this comment on that other question.

I have a script that is logging cURL's stderr to a file. We'll use this as an example:

curl -Lo /dev/null stackoverflow.com 2>/tmp/foo

When I inspect that file, it looks like this:

  % 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^M100   143  100   143    0     0   1190      0 --:--:-- --:--:-- --:--:--  1191
^M 97  244k   97  239k    0     0   688k      0 --:--:-- --:--:-- --:--:--  688k^M100  244k  100  244k    0     0   701k      0 --:--:-- --:--:-- --:--:-- 4974k

And that's total garbage to me. I want the statistics without the animated progress bar. I can parse it out with some standard unix tools. However, I'm thinking maybe some combination of arguments and/or termcap/terminfo may also work.

Please advise.


This simple post processing would work because it's not animated:

head -n2 /tmp/foo; tail -n1 /tmp/foo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  245k  100  245k    0     0   393k      0 --:--:-- --:--:-- --:--:--  393k
Bruno Bronosky
  • 66,273
  • 12
  • 162
  • 149

2 Answers2

0

If I don't get any better suggestions, I'm going to settle for this:

$ curl -Lo /dev/null --stderr >(awk 'END {print "Downloaded", $2, "of", $4, "at", $7"bps"}' >/tmp/foo) stackoverflow.com
$ cat /tmp/foo
Downloaded 245k of 245k at 472kbps
Bruno Bronosky
  • 66,273
  • 12
  • 162
  • 149
0

Since curl 7.67.0 (2019-11-06) there is --no-progress-meter, which does exactly this, and nothing else. From the man page:

   --no-progress-meter
         Option to switch off the progress meter output without muting or
         otherwise affecting warning and informational messages like  -s,
         --silent does.

         Note  that  this  is the negated option name documented. You can
         thus use --progress-meter to enable the progress meter again.

         See also -v, --verbose and -s, --silent. Added in 7.67.0.

So you can use:

curl -Lo /dev/null --no-progress-meter stackoverflow.com

That will print nothing on success, and the error on failure.

Gogowitsch
  • 1,181
  • 1
  • 11
  • 32