cURL: how to suppress strange output when redirecting?
Try this:
curl -vs -o /dev/null http://somehost/somepage 2>&1
That will suppress the progress meter, send stdout
to /dev/null
and redirect stderr
(the -v
output) to stdout
.
curl --fail --silent --show-error http://www.example.com/ > /dev/null
This will suppress the status dialog, but will otherwise output errors to STDERR.
user@host:~# curl http://www.yahoo.com > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 254k 0 254k 0 0 403k 0 --:--:-- --:--:-- --:--:-- 424k
The above outputs the status table when redirecting.
user@host:~# curl --fail --silent --show-error http://www.yahoo.com > /dev/null
The above suppresses the status table when redirecting, but errors will still go to STDERR.
user@host:~# curl --fail --silent --show-error http://www.errorexample.com > /dev/null
curl: (6) Couldn't resolve host 'www.errorexample.com'
The above is an example of an error to STDERR.
user@host:~# curl -v --fail --silent --show-error http://www.errorexample.com > ~/output.txt 2>&1
user@host:~# cat ~/output.txt
* getaddrinfo(3) failed for www.errorexample.com:80
* Couldn't resolve host 'www.errorexample.com'
* Closing connection #0
curl: (6) Couldn't resolve host 'www.errorexample.com'
Just add 2>&1 to the end to redirect STDERR to STDOUT (in this case, to a file).
According to man curl
:
-s, --silent : Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.
Example usage:
curl -s 'http://www.google.com'
or if you want to capture the HTTP-BODY into a variable in bash
BODY=$( curl -s 'http://www.google.com' )
echo $BODY
You can use -s
or --silent
interchangeably.