用curl来检查webservice的Linux脚本已经启动了

用curl来检查webservice的Linux脚本已经启动了,第1张

概述用curl来检查webservice的Linux脚本已经启动了

我有一个在http://localhost/test/testweb提供的web服务

我想写一个脚本来检查web服务是否curl

如果有一个给定的curl参数,则返回200 OK OK true false以便我可以使用它是if-else块在linux脚本中

Wireshark没有selectcURL命令

用Curl或者Python获取Span值(但是当我这样做的时候是空的)?

PHP cURL本地工作,AWS服务器上的错误77

SSL对等证书或SSH远程密钥不正确

如何在shell脚本中使用curl?

连接保持活着的问题

(linux Cli PHP)在执行期间将CURL的详细输出捕获到文件

curl:(2)初始化失败

windowscurlstring格式

需要从日志中读取数据… tail,grep和inotifywait

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

-s =无声的cURL输出

-L =遵循重定向

-w =自定义输出格式

-o =将HTML输出重定向到/dev/null

例:

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

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

这将通过wget 2>&1管道检查标题stderr到stdout grep filters -O /dev/null只是抛出页面的内容

if [ "`wget http://example.org/ -O /dev/null -S --quIEt 2>&1 | grep '200 OK'`" != "" ]; then echo Hello; fi;

我知道不卷曲,但仍然是一个解决方案

我需要更好的答案,所以我写了下面的脚本。

伪造的短语用于检测ISP“搜索协助”广告软件的http请求。

#!/bin/bash fakePhrase="verizon" siteList=( 'http://Google.com' 'https://Google.com' 'http://wikipedia.org' 'https://wikipedia.org' 'http://cantgettherefromhere' 'http://searchassist.verizon.com' ) exitStatus=0 function isUp { http=`curl -sL -w "%{http_code}" "$1" -o temp_isUp` fakeResponse=`cat temp_isUp | grep $fakePhrase` if [ -n "$fakeResponse" ]; then http=$fakePhrase fi case $http in [2]*) ;; [3]*) echo 'Redirect' ;; [4]*) exitStatus=4 echo "$1 is DENIED with ${http}" ;; [5]*) exitStatus=5 echo "$1 is ERROR with ${http}" ;; *) exitStatus=6 echo "$1 is NO RESPONSE with ${http}" ;; esac } for var in "${siteList[@]}" do isUp $var done if [ "$exitStatus" -eq "0" ]; then echo 'All up' fi rm temp_isUp exit $exitStatus

用这个:

curl -o $CURL_OUTPUT -s -w %{http_code}\n%{time_total}\n $URL > $TMP_file 2>&1 cat $TMP_file

同@burhan-khalID补充说:

--connect-timeout 3 --max-time 5

test_command='curl -sL -w "%{http_code}\n" "http://www.Google.com:8080/" -o /dev/null --connect-timeout 3 --max-time 5' if [ $(test_command) == "200" ] ; then echo "OK" ; else echo "KO" ; fi

总结

以上是内存溢出为你收集整理的用curl来检查webservice的Linux脚本已经启动了全部内容,希望文章能够帮你解决用curl来检查webservice的Linux脚本已经启动了所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1294266.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-10
下一篇2022-06-10

发表评论

登录后才能评论

评论列表(0条)

    保存