检测一个主机的运行状态
#!/bin/bash
# 用于检测一个主机的运行状态。使用ping命令,当ping了四次有三次是出现ping不成功的,则报警。并且ping的频率是秒级别的
set -x
# 每隔三秒执行一次
success_count=0
for ((i=1;i<4;i++));do
if ping -c1 $1 &>/dev/null;then
let success_count++
fi
sleep 3s
done
echo "success_count is $success_count"
if [ 3 -eq $success_count ];then
echo "$1 is up"
else
echo "$1 is down"
fi
set +x