Determine if the remote Web server status code is healthy through scripting

Source: Internet
Author: User
Tags nginx server

Determine if the remote Web server status code is healthy through scripting


    1. 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

    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.