CPE网络中断自动重启
家里CPE老是时不时就没网了,需要重启才好使,每次手动重启有点麻烦,今天写个脚本。
vi /etc/check_network.sh
写入
#!/bin/sh
TARGET="223.5.5.5"
INTERVAL=1
FAIL_COUNT=0
MAX_FAIL=10
LOG_FILE="/opt/network_check.log"
while true; do
if ping -c 1 $TARGET > /dev/null 2>&1; then
FAIL_COUNT=0
else
FAIL_COUNT=$((FAIL_COUNT + 1))
echo "$(date): Network is down, fail count: $FAIL_COUNT" >> $LOG_FILE
fi
if [ $FAIL_COUNT -ge $MAX_FAIL ]; then
echo "$(date): $MAX_FAIL consecutive ping failures, rebooting..." >> $LOG_FILE
/sbin/reboot
FAIL_COUNT=0
fi
sleep $INTERVAL
done
这个脚本是每隔1秒检测一下到223.5.5.5通不通,连续10次不通就重启。启动脚本
vi /etc/init.d/check_network
写入
#!/bin/sh /etc/rc.common
START=99
start() {
/etc/check_network.sh &
}
自启动
/etc/init.d/check_network enable
/etc/init.d/check_network start
阅读剩余
版权声明:
作者:konoha
链接:https://konoha.cc/cpe%e7%bd%91%e7%bb%9c%e4%b8%ad%e6%96%ad%e8%87%aa%e5%8a%a8%e9%87%8d%e5%90%af.html
文章版权归作者所有,未经允许请勿转载。
THE END