shell脚本检测网络是否畅通
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脚本检测网络是否畅通的更多相关文章
- 多线程shell脚本检测主机存活
局域网中分了很多网段,而IP地址使用情况也未知,前期也没有规划和记录,当新的主机需要使用固定IP的时候,能否第一时间知道哪个IP空闲就显得很重要了,如果一个一个去ping的话太浪费时间. 这里分享一个 ...
- linux shell脚本检测硬盘磁盘空间 邮件报警
使用 http://www.weiruoyu.cn/?p=368 shell脚本监控硬盘空间剩余空间 邮件报警 1.先观察一下磁盘,和如何使用脚本 [root@localhost ~]# df -h ...
- WyBox使用shell脚本检测io口是否正常
1. 修改mt7620a.dts文件,把gpio管脚复用全都定义为通用gpio /dts-v1/; /include/ "mt7620a.dtsi" / { compatible ...
- shell脚本检测监控mysql的CPU占用率
网站访问量大的时候mysql的压力就比较大,当mysql的CPU利用率超过300%的时候就不能提供服务了,近乎卡死状态,这时候最好的方法 就是重启mysql服务.由于这种事具有不可预见性,我们不知道什 ...
- Shell脚本检测Tomcat是否正在运行
#!/bin/sh # configurations # computer 设备名称 # target 监控目标 # watcher 跟踪者(邮箱) computer="ehetong&qu ...
- Shell脚本检测程序,如果挂了就重启程序
脚本如下: #!/bin/sh #要检查的进程名 PROGRESS_NAME="heihu_server" #----------------------------------- ...
- Shell脚本检测文件夹是否已被挂载的方法
方法1: if grep -qs '/mnt/foo' /proc/mounts; then echo "It's mounted." else echo "It's n ...
- shell脚本检测局域网内存活主机
<1> d211 admin # for i in {3..254} ; do ping -c 1 192.168.1.$i &>/dev/null && e ...
- shell脚本查看网络配置
#!/bin/bash ifconfig|grep -E 'eth|inet'|grep -Ev '(inet6|127.0.0.1)'|sed 's/ /\n/g'|awk NF|grep -Ev ...
随机推荐
- UVA 10940 Throwing cards away II
题意略: 先暴力打表发现规律 N=1 ans=1N=2 ans=2N=3 ans=2N=4 ans=4N=5 ans=2N=6 ans=4N=7 ans=6N=8 ans=8N=9 ans=2N=10 ...
- Sigslot介绍
最近在看delta3d开源引擎,最底层封装的消息机制,是基于其has_slots,搜索了一下其资料发现是一个很好用的C++库,先对其简单介绍一下. 首先说下插槽机制. 插槽系统常用的有三种:boost ...
- poj 1981(单位圆覆盖最多点问题模板)
Circle and Points Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 7327 Accepted: 2651 ...
- org.hibernate.HibernateException: Unable to get the default Bean Validation factor
org.hibernate.HibernateException: Unable to get the default Bean Validation factor这个异常需要在hibernate.c ...
- 使用Laravel将数据Excel导出的方法
1.copmposer下载maatwebsite/excel 2.在控制器引入:use Excel; 3.将要导出的数据处理成数组,第一组数据为表的字段名,如图 4.导出成表格 Excel::crea ...
- [BZOJ4990][Usaco2017 Feb]Why Did the Cow Cross the Road II dp
4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II Time Limit: 10 Sec Memory Limit: 128 MBSubmi ...
- 洛谷——P1403 [AHOI2005]约数研究
P1403 [AHOI2005]约数研究 题目描述 科学家们在Samuel星球上的探险得到了丰富的能源储备,这使得空间站中大型计算机“Samuel II”的长时间运算成为了可能.由于在去年一年的辛苦工 ...
- HDU 5916: Harmonic Value Description
题目描述 The harmonic value of the permutation $p_1,p_2,\cdots p_n$ is$$\sum_{i=1}^{n-1} gcd(p_i.p_{i+1} ...
- bzoj 1067: [SCOI2007]降雨量
题目链接: bzoj 1067: [SCOI2007]降雨量 题解: 很简单的一道题,但代码里有许多细节需要注意,切容易出错,调了三个小时OTZ 做一个st表维护区间最大值就 在获得年份在序列中的po ...
- bzoj 4338: BJOI2015 糖果
4338: BJOI2015 糖果 Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 200 Solved: 93[Submit][Status][Dis ...