#!/bin/sh
IP="10.10.100.1"
kill_deamon() {
/etc/init.d/deamon stop
}
start_deamon(){
/etc/init.d/deamon start
}
check_ping() {
local total="0"
local i="0"
while [ $i -lt 10 ]; do
local line=""
#echo "ping $IP"
line=`ping $IP -c 1 -s 1 -W 1 | grep "100% packet loss" | wc -l`
if [ "${line}" != "0" ]; then
echo "ping failed!"
total=$((total+1))
else
echo "ping ok!"
total="0"
fi
i=$((i+1))
sleep 1
done
if [ $total -gt 5 ]; then
echo "check failed!"
return 1
else
echo "check ok!"
return 0
fi
}
start(){
local rtl=""
while [ 1 ]; do
check_ping
rtl=$?
if [ "$rtl" != "0" ]; then
echo " restart deamon start "
kill_deamon
start_deamon
else
sleep 600;
fi
done
}
start
其它的也有这样的,如下,都是用一个循环去判断而已:
#!/bin/sh
line="0"
total="0"
dst=`uci get network.mesh.gateway`
while [ 1 ]; do
line=`ping $dst -c 1 -s 1 -W 1 | grep "100% packet loss" | wc -l`
if [ "${line}" != "0" ]; then
total=$((total+1))
else
total="0"
fi
if [ "${total}" == "5" ]; then
reboot -f
fi
sleep 12
done
另外一个:
#!/bin/bash
for siteip in $(seq 1 254)do
site="192.168.1.${siteip}"
ping -c1 -W1 ${site} &> /dev/null
if [ "$?" == "0" ]; then
echo "$site is UP"
else
echo "$site is DOWN"
fi
done
推荐本站淘宝优惠价购买喜欢的宝贝:
本文链接:https://hqyman.cn/post/390.html 非本站原创文章欢迎转载,原创文章需保留本站地址!
休息一下~~