这有的写法不符合我的习惯,直接拿来用就好
#!/bin/bash
#检测网络链接畅通
function network()
{
#超时时间
local timeout=1
#目标网站
local target=www.baidu.com
#获取响应状态码
#head tail
local ret_code=`curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code} | tail -n1`
if [ "x$ret_code" = "x200" ]; then
#网络畅通
return 1
else
#网络不畅通
return 0
fi
return 0
}
network
if [ $? -eq 0 ]
then
echo -e "\033[1;42;33m 网络不畅通,请检查网络设置! \033[0m"
else
echo -e "\033[1;42;33m 网络畅通,你可以上网冲浪! \033[0m"
fi
#sleep 1000000000
exit 0