Linux Ping实现停电关机脚本

By | 2021 年 7 月 13 日

路由器IP地址192.168.5.1,没有接UPS。
把下面脚本写到/root/powercheck.sh并chmod +x /root/powercheck.sh赋予执行权限。
crontab -e 添加 * * * * * /root/powercheck.sh 每分钟执行。

#!/bin/sh
ret=`ping -c 3 192.168.5.1 | grep '0 received' | wc -l`
if [ $ret -eq 0 ];
then
  echo 'AC Power OK' > /root/powertest.txt
else
  poweroff 
fi

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注