带有curl的Linux脚本,用于检查Web服务是否已启动 [英] Linux script with curl to check webservice is up

查看:534
本文介绍了带有curl的Linux脚本,用于检查Web服务是否已启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在http://localhost/test/testweb

我想编写一个脚本来检查web服务是否已卷曲

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

如果提供了curl参数,则返回200 OK ok true false,这样我就可以在Linux脚本中使用if-else块

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

推荐答案

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

  • -s =静音cURL的输出
  • -L =跟随重定向
  • -w =自定义输出格式
  • -o =将HTML输出重定向到/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" "http://www.google.com/" -o /dev/null
      200
      

      如果要捕获输出,我可能会删除\\n.

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

      这篇关于带有curl的Linux脚本,用于检查Web服务是否已启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆