|
|
楼主 |
发表于 2020-7-30 21:35
|
显示全部楼层
cd /tmp/ups # 切换目录到 /tmp/ups
tee netcheck.sh <<-'EOF'
#!/bin/env bash
#MonitorIP=192.168.1.2
Monitor1=BRN3C2AXXXXXXX
Monitor2=uplus-haier-1814-XXXXX
DelayTime=150s
if ping $Monitor1 -W 2 -w 2 -c 2 | grep ' bytes from ' > /dev/null
then
echo "$(date -d today +"%Y-%m-%d %H:%M:%S"):连接打印机正常。" | tee -a /tmp/ups/PowerLog.txt
else
echo "$(date -d today +"%Y-%m-%d %H:%M:%S"):连接打印机失败,稍候测试燃气热水器 。。。" | tee -a /tmp/ups/PowerLog.txt
sleep $DelayTime
if ping $Monitor2 -W 2 -w 2 -c 2 | grep ' bytes from ' > /dev/null
then
echo "$(date -d today +"%Y-%m-%d %H:%M:%S"):连接燃气热水器成功,退出复检。" | tee -a /tmp/ups/PowerLog.txt
else
echo "$(date -d today +"%Y-%m-%d%H:%M:%S"):连接2个设备均失败,NAS 1分钟后关机。" | tee -a /tmp/ups/PowerLog.txt
cp -f /tmp/ups/PowerLog.txt /volume1/Software/PowerLog.txt
shutdown -P +1
fi
fi
exit 0
EOF
find /volume1/Software/ -iname PowerLog.txt -size +100k -exec ture > /volume1/Software/PowerLog.txt \;
sleep 2s #日志文件超过100K时,清空内容。
cp -f /volume1/Software/PowerLog.txt /tmp/ups/PowerLog.txt
chmod 666 /tmp/ups/PowerLog.txt |
|