root@localhost:~# curl -I http://192.168.100.115
HTTP/1.1 200 OK
Server: nginx/1.10.3 (Ubuntu)
Date: Tue, 25 Jun 2019 11:43:31 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 12 Jun 2019 06:36:15 GMT
Connection: keep-alive
ETag: "5d009d5f-264"
Accept-Ranges: bytes
通常我们在监控Web服务的时候,可以根据Web的HTTP状态码来判断Web服务是否工作正常,如果我们使用grep过滤第一行,会发现会输出很多不必要的信息:
root@localhost:~# curl -I http://192.168.100.115 | grep -E 'HTTP|200 OK'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 612 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
HTTP/1.1 200 OK
解决方法一
root@localhost:~# curl -I -s http://192.168.100.115 | grep -E 'HTTP|200 OK'
HTTP/1.1 200 OK
-s
是沉默,静默模式,意思为不输出进度表或错误信息;
解决方法二
root@localhost:~# curl -s -w "%{http_code}" -o /dev/null http://192.168.100.115
解决方法三
root@localhost:~# curl -I http://192.168.100.115 2>/dev/null|head -n1
HTTP/1.1 200 OK