2

I'm using the following command in a script:

curl -O --time-cond $_input_file_name $_location/$_input_file_name

and it produces a report with this heading:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed

but it seems to be sent to error output, even though the transfer has been successful and the return code from curl is zero. Why does it do this? Is there a way to suppress this without suppressing actual error messages? Adding -s or -sS to the curl command doesn't seem to alter this behaviour.

Running the command in a terminal, the -s option does suppress the output. The problem arises only within a script. The script is being triggered in crontab via cronic.

I'm working in Debian 9.1 with curl 7.52.1 (x86_64-pc-linux-gnu).

mbrampton
  • 125
  • 1
  • 6
  • Possible duplicate of [Making curl send errors to stderr and everything else to stdout](https://stackoverflow.com/questions/6935006/making-curl-send-errors-to-stderr-and-everything-else-to-stdout) – sal Aug 13 '17 at 10:03

2 Answers2

4

Curl was designed, at least originally, to send its output to stdout by default (see here), something a large number of other Unix utilities also do.

Some programs will allow you to write their output to stdout by specifying - as an output file name but this is not the way curl went.

The reason all the progress messages would therefore need to be sent to stderr would be so they don't corrupt your actual stream of data coming out on stdout.

If you examine the man page, you should see that the --silent --show-error options should disable the progress stuff while still showing an error.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
0

Use "-s -S"

   -S, --show-error
          When used with -s, --silent, it makes curl show an error message if it fails.

   -s, --silent
          Silent  or quiet mode. Don't show progress meter or error messages.  Makes Curl mute. It will still out-
          put the data you ask for, potentially even to the terminal/stdout unless you redirect it.

          Use -S, --show-error in addition to this option to disable progress meter but still show error messages.

          See also -v, --verbose and --stderr.
Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69
  • Thanks, but doesn't seem to work in a script. I have clarified the question. And why is it sent to error output? I want error messages, but not the progress report. – mbrampton Aug 13 '17 at 09:20
  • AFAIK that's the answer. I suggest trying to prove that you are actually changing the crontab – Yuri Schimke Aug 13 '17 at 10:02
  • Thanks, you're kind of right and that certainly helped me! It's not the crontab that is changing, it is a script within a script within a script. Unfortunately, I'd failed to notice there are two curl uses. But I do feel that paxdiablo's answer helps me more to understand what is going on. – mbrampton Aug 13 '17 at 17:24