curl获取http返回的状态码

方式一

curl -I -s -m 10 http://192.158.1.11:8080/test/ |grep HTTP|awk '{print $2}'

方式二

curl -I -o /dev/null -s -w %{http_code} http://192.168.195.129:8080

-I  仅输出HTTP请求头

-s 不输出任何东西

-m 设置请求超时时间,单位/秒

以下是脚本分步执行结果

[root@2 test]# curl  -i -s http://192.158.1.11:8080/test/      ##调用页面
HTTP/1.1 200 
Set-Cookie: JSESSIONID=00553C870452B5D8527ACCAB3DAF55FA; Path=/QZ-BKSQ; HttpOnly
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Last-Modified: Sat, 23 Oct 2021 07:03:37 GMT
Accept-Ranges: bytes
Content-Type: text/html;charset=ISO-8859-1
Content-Language: en-US
Content-Length: 194
Date: Tue, 30 Nov 2021 04:14:26 GMT


 

 
  succeed
  
 




SUCCEED~, BKSQ部署成功!

[root@2 test]# curl -i -s http://192.158.1.11:8080/test/ |grep HTTP ##调用页面,查找http请求头所在行 HTTP/1.1 200 [root@2 test]# curl -i -s http://192.158.1.11:8080/test/ |grep HTTP|awk '{print $2}' ##在请求头中截取状态码 200 [root@2 test]#

你可能感兴趣的:(运维,linux,shell,运维,http,shell)