停电UPS供电情况下自动关机

action=`ping -c 20 -W 1 192.168.1.1 | grep received | awk '{print $4}'`

if [ $action -eq 0 ];then
echo `date`  "Check Gateway Fail!" >> /var/log/power.log
shutdown -p now
else
echo `date`  "Power OK" >> /var/log/power.log
fi

编程技巧