Post

Using curl to show error only

Using curl to show error only

When you’re using curl in a shell script and only care whether a request succeeded or failed — not the response body — this combination of flags is what you want. The --show-error flag is the key one: without it, --silent will also swallow error messages, leaving you completely blind to failures.

  • curl
1
$ curl --insecure --silent --output /dev/null --show-error https://url.bla.com:8443/api/bla

Use –insecure only if you trust the endpoint as curl will ignore any ssl errors

–silent and –output is to quetly route all output to /dev/null

–show-error is to display any error message like “curl: (7) Failed to connect to url.bla.com port 8443: Connection refused”

This post is licensed under CC BY 4.0 by the author.