#! /bin/bash
n=0
while true
do
ping 183.1.0.113 -c 1 -W 1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "访问不通"
if [ "$n" -gt 4 ];then
echo -e "\033[1;31m可能断电,即将关机\033[0m\n"
echo -e "`date +"%Y-%m-%d %H:%M:%S"`\t\c" >> /home/log/duandian.log
echo -e "\033[1;31m可能断电,即将关机\033[0m\n\n" >> /home/log/duandian.log
shutdown -h now
fi
let n=n+1
else
echo -e "\033[1;31m市电正常\033[0m\n"
sleep 1
fi
done
监测断电
最新推荐文章于 2021-03-07 18:31:23 发布