shell初始化安装脚本执行时,需从网络上安装一些rpm包,所有需要先检测网络的畅通性,

代码

#检测网络链接&&ftp上传数据
function networkAndFtp()
{
#超时时间
timeout= #目标网站
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
}

实际脚本:

#判断网络是否配置正确,如果网络不通,退出安装程序

net_status=`curl -I -s --connect-timeout  www.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
else
echo -e "\033[31m\033[01m[ ##########the network connecting is unstable, please check the network firstly ,then start the install again . 网络连接有问题,安装即将退出,请检查网络后再次安装########## ]\033[0m"
sleep
exit
fi

IDC机房到阿里云vpc网络ping网络连通性

配置zabbix客户端配置文件

vim /etc/zabbix/zabbix_agentd.conf

添加  Include=/etc/zabbix/zabbix_agentd.d/

cat net_status.sh
#!/bin/bash #判断网络延时 idc机房到阿里云vpc网络 #设置环境变量
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
export PATH while getopts "c:i:" opt; do
case $opt in
c)
count=$OPTARG
;;
i)
ips=$OPTARG
;;
\?)
;;
esac
done tmp_fifofile="/tmp/ping.fifo"
mkfifo $tmp_fifofile
exec 6<>$tmp_fifofile
rm $tmp_fifofile for ((i=0;i<20;i++));do
echo
done >&6 for ip in `echo $ips |awk -F'|' '{ for(i=1;i<=NF;i++) {print $i} }'`
do
read -u 6
{
rtt=`ping -c $count $ip |grep rtt |awk '{print $4}' |awk -F'/' '{print $2}'`
rtt=${rtt:-'0'}
echo $rtt
}&
echo >&6
done wait
exec 6>&-

  

[root@gpu007 zabbix_agentd.d]# cat zhiyi.conf 

UserParameter=net_status,/etc/zabbix/scripts/net_status.sh -c 4 -i 192.168.0.167

  

zabbix 客户端重新启动 zabbix-agent

[root@compute zabbix_agentd.d]# systemctl restart zabbix-agent

在 zabbix server 端添加 相应的item

添加相应的trigger

添加相应的graphs

shell脚本检测网络是否畅通的更多相关文章

  1. 多线程shell脚本检测主机存活

    局域网中分了很多网段,而IP地址使用情况也未知,前期也没有规划和记录,当新的主机需要使用固定IP的时候,能否第一时间知道哪个IP空闲就显得很重要了,如果一个一个去ping的话太浪费时间. 这里分享一个 ...

  2. linux shell脚本检测硬盘磁盘空间 邮件报警

    使用 http://www.weiruoyu.cn/?p=368 shell脚本监控硬盘空间剩余空间 邮件报警 1.先观察一下磁盘,和如何使用脚本 [root@localhost ~]# df -h ...

  3. WyBox使用shell脚本检测io口是否正常

    1. 修改mt7620a.dts文件,把gpio管脚复用全都定义为通用gpio /dts-v1/; /include/ "mt7620a.dtsi" / { compatible ...

  4. shell脚本检测监控mysql的CPU占用率

    网站访问量大的时候mysql的压力就比较大,当mysql的CPU利用率超过300%的时候就不能提供服务了,近乎卡死状态,这时候最好的方法 就是重启mysql服务.由于这种事具有不可预见性,我们不知道什 ...

  5. Shell脚本检测Tomcat是否正在运行

    #!/bin/sh # configurations # computer 设备名称 # target 监控目标 # watcher 跟踪者(邮箱) computer="ehetong&qu ...

  6. Shell脚本检测程序,如果挂了就重启程序

    脚本如下: #!/bin/sh #要检查的进程名 PROGRESS_NAME="heihu_server" #----------------------------------- ...

  7. Shell脚本检测文件夹是否已被挂载的方法

    方法1: if grep -qs '/mnt/foo' /proc/mounts; then echo "It's mounted." else echo "It's n ...

  8. shell脚本检测局域网内存活主机

    <1> d211 admin # for i in {3..254} ; do ping -c 1 192.168.1.$i &>/dev/null && e ...

  9. shell脚本查看网络配置

    #!/bin/bash ifconfig|grep -E 'eth|inet'|grep -Ev '(inet6|127.0.0.1)'|sed 's/ /\n/g'|awk NF|grep -Ev ...

随机推荐

  1. shell脚本查看服务器基本信息

    #!/bin/sh #电脑概览 #电脑型号 ComputerModel=`/usr/bin/sudo /usr/sbin/dmidecode | grep -A2 "System Infor ...

  2. SSM整合过程中出现的问题

    1.Caused by: java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DataSourceTransac ...

  3. java的unity单元测试

    import org.junit.After; import org.junit.Before; import org.junit.Test; public class TestUnit { publ ...

  4. 将ros中suscriber和publisher写入class中

    相比于笨拙的全局变量和全局函数,将suscriber和publisher成一个class,形式更加简洁和容易管理,一个节点就是一个类 参考资料 http://answers.ros.org/quest ...

  5. Ubuntu安装java环境

    Ubuntu安装java环境 1.添加ppa sudo add-apt-repository ppa:webupd8team/java sudo apt-get update 2.安装oracle-j ...

  6. laravel 安装碰到的问题:全局安装 Laravel Installer,然后用下面的指令创建新项目: laravel new blog报连接超时解决方案

    在执行laravel new project 的时候报错 cURL error 7: Failed to connect to cabinet.laravel.com port 80: Timed o ...

  7. Spfa【p1186】 玛丽卡

    Description 麦克找了个新女朋友,玛丽卡对他非常恼火并伺机报复. 因为她和他们不住在同一个城市,因此她开始准备她的长途旅行. 在这个国家中每两个城市之间最多只有一条路相通,并且我们知道从一个 ...

  8. 体验VisualStudio 2013中的内存分析功能

    内存分析一直是个比较令人头痛的问题,Visual Studio 2013中就集成了一个内存分析的功能,可以方便我们进行分析内存的占用情况.本文将简单的介绍一下如何使用这个功能. 首先以一个简单的程序为 ...

  9. What is the purpose of mock objects?

    Since you say you are new to unit testing and asked for mock objects in "layman's terms", ...

  10. Go -- 在Go语言中使用JSON struct

    Encode 将一个对象编码成JSON数据,接受一个interface{}对象,返回[]byte和error: func Marshal(v interface{}) ([]byte, error) ...