Determine if the remote Web server status code is healthy through scripting
Description
(1) A list of common HTTP status codes for production environments, please check out my blog: http://wutengfei.blog.51cto.com/10942117/1934645
(2) Remote NGINX server IP address in experiment: 192.168.100.114
Local client IP address: 192.168.100.118
- The script is as follows
Method 1:if
#!/bin/bash
Httpcode= ' curl-i-S 192.168.100.114|head-1|cut-d ""-f2 '
If ["$httpcode" = = "];then"
echo "Nginx is running."
Else
echo "Nginx is not running."
Fi
The validation results are as follows:
Open Nginx Service
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9B/B8/wKiom1lmMUOB2nAXAAANTG3xlxk248.png "title=" 11. PNG "alt=" Wkiom1lmmuob2naxaaantg3xlxk248.png "/>
Execute the script on the client:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9B/B8/wKiom1lmMYqRx47cAAAJRXT2nq0061.png "title=" 11. PNG "alt=" Wkiom1lmmyqrx47caaajrxt2nq0061.png "/>
Now close Nginx Service:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9B/B8/wKiom1lmMfaDpi6bAAAWBZvSb34855.png "title=" 11. PNG "alt=" Wkiom1lmmfadpi6baaawbzvsb34855.png "/>
Execute the script on the client:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9B/B7/wKioL1lmMlewhffLAAAJ74AnXAQ995.png "title=" 11. PNG "alt=" Wkiol1lmmlewhfflaaaj74anxaq995.png "/>
Method 2: Use the pass-through parameter
#!/bin/bash
If [$#-ne 1];then
echo "usage:$0 IP port."
Fi
Httpcode= ' curl-i-S $1|head-1|cut-d ""-f2 '
If ["$httpcode" = = "];then"
echo "Nginx is running."
Else
echo "Nginx is not running."
Fi
The validation results are as follows:
Open Nginx Service
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9B/B8/wKiom1lmMUOB2nAXAAANTG3xlxk248.png "title=" 11. PNG "alt=" Wkiom1lmmuob2naxaaantg3xlxk248.png "/>
Execute the script on the client:
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9B/B8/wKioL1lmOMSg6Iz6AAALjClRT6g702.png "title=" 11. PNG "alt=" Wkiol1lmomsg6iz6aaaljclrt6g702.png "/>
Now close Nginx Service:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9B/B8/wKiom1lmMfaDpi6bAAAWBZvSb34855.png "title=" 11. PNG "alt=" Wkiom1lmmfadpi6baaawbzvsb34855.png "/>
Execute the script on the client:
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9B/B9/wKiom1lmOSTxnkybAAANdoZY5QM869.png "title=" 11. PNG "alt=" Wkiom1lmostxnkybaaandozy5qm869.png "/>
Method 3: Using read, the interface is relatively friendly
#!/bin/bash
Read-p "Please input IP:" A
If [-Z $a];then
echo "usage:$0 please input IP."
Fi
Httpcode= ' curl-i-S $a |head-1|cut-d ""-f2 '
If ["$httpcode" = = "];then"
echo "Nginx is running."
Else
echo "Nginx is not running."
Fi
The validation results are as follows:
Open Nginx Service
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9B/B8/wKiom1lmMUOB2nAXAAANTG3xlxk248.png "title=" 11. PNG "alt=" Wkiom1lmmuob2naxaaantg3xlxk248.png "/>
Execute the script on the client:
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9B/B9/wKiom1lmOuqiWCfdAAAOh5PnW2k901.png "title=" 11. PNG "alt=" Wkiom1lmouqiwcfdaaaoh5pnw2k901.png "/>
Now close Nginx Service:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9B/B8/wKiom1lmMfaDpi6bAAAWBZvSb34855.png "title=" 11. PNG "alt=" Wkiom1lmmfadpi6baaawbzvsb34855.png "/>
Execute the script on the client:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9B/B8/wKioL1lmO0WxJrA-AAAPqRodhRM887.png "title=" 11. PNG "alt=" Wkiol1lmo0wxjra-aaapqrodhrm887.png "/>
Method 4: Use the function
#!/bin/bash
[-f/etc/init.d/functions] &&. /etc/init.d/functions | | Exit 1
Read-p "Please input IP:" A
Httpcode= ' curl-i-S $a |head-1|cut-d ""-f2 '
If ["$httpcode" = = "];then"
Action "Nginx is running."/bin/true
Else
Action "Nginx is not running."/bin/false
Fi
The validation results are as follows:
Open Nginx Service
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9B/B8/wKiom1lmMUOB2nAXAAANTG3xlxk248.png "title=" 11. PNG "alt=" Wkiom1lmmuob2naxaaantg3xlxk248.png "/>
Execute the script on the client:
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9B/B8/wKioL1lmPoKBLO6rAAAQeUGlLVk564.png "title=" 11. PNG "alt=" Wkiol1lmpokblo6raaaqeugllvk564.png "/>
Now close Nginx Service:
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9B/B8/wKiom1lmMfaDpi6bAAAWBZvSb34855.png "title=" 11. PNG "alt=" Wkiom1lmmfadpi6baaawbzvsb34855.png "/>
Execute the script on the client:
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9B/B9/wKiom1lmPuqyiQgeAAAQodDkXI8010.png "title=" 11. PNG "alt=" Wkiom1lmpuqyiqgeaaaqoddkxi8010.png "/>
This article is from the "Hand of the Paladin Control" blog, please make sure to keep this source http://wutengfei.blog.51cto.com/10942117/1946907
Determine if the remote Web server status code is healthy through scripting