Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

Linux script with curl to check webservice is up

I have a webservice provided at http://localhost/test/testweb

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

question from:https://stackoverflow.com/questions/12747929/linux-script-with-curl-to-check-webservice-is-up

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
curl -sL -w "%{http_code}\n" "http://www.google.com/" -o /dev/null
  • -s = Silent cURL's output
  • -L = Follow redirects
  • -w = Custom output format
  • -o = Redirects the HTML output to /dev/null

Example:

[~]$ curl -sL -w "%{http_code}\n" "http://www.google.com/" -o /dev/null
200

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...