Shell script detects if the network is unblocked

Source: Internet
Author: User
Tags curl

When the shell initializes the installation script, it is necessary to install some RPM packages from the network, all of which need to detect the smoothness of the network first.

Code

#检测网络链接 &&FTP upload Datafunctionnetworkandftp () {#超时时间 timeout=5#目标网站 Target=www.baidu.com #获取响应状态码 Ret_code= ' Curl-i-s--connect-timeout $timeout $target-W%{http_code} |Tail-N1 'if["X$ret_code"="x200"]; Then#网络畅通Else#网络不畅通fi  }  

Actual script:

#判断网络是否配置正确, if the network does not pass, exit Setup Net_status= ' Curl-i-S--connect-timeout5Www.baidu.com-W%{http_code} |Tail-N1 'if[$net _status-eq $]; Then      Echo-E"\033[32m[######## #the Network connecting is normal, installing now############]\033[0m"      Sleep 1Else      Echo-E"\033[31m\033[01m[######### #the Network connecting is unstable, please check the network firstly and then start the Insta ll again. There is a problem with the network connection, the installation is about to exit, please check the network and install ##########]\033[0m"     Sleep 1Exit1fi

Shell script detects if the network is unblocked

Related Article

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.