買了個山特的SANTAK TG-BOX 850 UPS,自帶USB通訊線纜。本以為官方軟件提供Linux下的CLI命令以監控UPS狀態.
官網提供的下載鏈接巨慢無比不說,CLI下只提供了安裝腳本,沒有狀態監控程序。我TM……
算了,當個非管理型的UPS用吧。搜索了下網上提供的腳本,感覺寫的都不太合適。自己重新修改了一下。
#!/bin/sh while true do ping -c 1 192.168.50.2 > /dev/null ret=$? if [ $ret -ne 0 ] 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 180 ping -c 1 192.168.50.2 > /dev/null ret=$? if [ $ret -ne 0 ] 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.