mmc18 mmc18 - 2 years ago 105
Linux Question

Linux script with curl to check webservice is up

I have a webservice provided at


I want to write a script to check if webservice is up with curl

If there a curl parameter given, returns
200 OK
ok true false so that I can use it is if-else block in linux script

Answer Source
curl -sL -w "%{http_code}\\n" "" -o /dev/null
  • -s = Silent cURL's output
  • -L = Follow redirects
  • -w = Custom output format
  • -o = Redirects the HTML output to /dev/null


[~]$ curl -sL -w "%{http_code}\\n" "" -o /dev/null

I would probably remove the \\n if I were to capture the output.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download