Return only a HTTP status code from curl command
Solution 1:
You can use the -w
parameter to define the format curl
outputs. To get the status code and nothing else, use something like this:
$ curl -s -o /dev/null -w "%{http_code}" http://xxx.xxx.xxx
The output should look like this:
$ curl -s -o /dev/null -w "%{http_code}" https://www.google.com
200
Note, the -o
defines that the output for the page will be sent to /dev/null - this way it will only print out the status code and not the page contents.