买了个山特的SANTAK TG-BOX 850 UPS,自带USB通讯线缆。本以为官方软件提供Linux下的CLI命令以监控UPS状态.

官网提供的下载链接巨慢无比不说,CLI下只提供了安装脚本,没有状态监控程序。我TM……

算了,当个非管理型的UPS用吧。搜索了下网上提供的脚本,感觉写的都不太合适。自己重新修改了一下。

#!/bin/sh
while true
do
ping -c 192.168.50.2 > /dev/null
ret=$?
if [ $ret -ne ]
then
echo -e "AC POWER LOSS! UPS WORKING NOW!\n-------------------------------\nSave your jobs and a further check will be execute in 3 mins,if it still loss,system will be shutdown immediately!" | wall
sleep
ping -c 192.168.50.2 > /dev/null
ret=$?
if [ $ret -ne ]
then
echo -e "AC POWER STILL LOSS! SYSTEM WILL SHUTDOWN NOW" | wall
poweroff
fi
fi
sleep 5
done

然后把ups.sh的功能注册成服务,方便操作:

新建/usr/lib/systemd/system/ups.service

[Unit]
Description=UPS monitor and shutdown automaticlly
After=network.target [Service]
Type=simple
User=root
ExecStart=nohup /root/ups.sh &
ExecStop=/bin/kill $MAINPID
PrivateTmp=true [Install]
WantedBy=multi-user.target

启动服务:

systemctl start ups.service

让服务开机自动运行

systemctl enable ups.service

done.

05-11 22:03