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