UPS Power-Outage Auto Shutdown Script for Linux

For UPS devices without serial/network signaling, this script-based method can automatically detect external power outage and shut down Linux safely.

Principle

Use a network target that loses connectivity when mains power fails. If ping fails continuously for a configured period, trigger shutdown.

Cron Schedule

Run as root (requires shutdown permission):

1
* * * * * /root/detect_ups.sh >> /var/log/detect_ups.log

Script Example

/root/detect_ups.sh

1
2
#!/bin/bash
# check ping target and shutdown when outage condition is met
记录并分享
Built with Hugo
Theme Stack designed by Jimmy