Linux Shutdown on Low Battery

This script uses the nut set of tools for managing and monitoring a UPS. You should run this script every minute as a cron job.

1
2
3
4
5
6
7
8
#!/bin/bash
BATTERY=`/bin/upsc [email protected] | /bin/grep 'battery.charge:' | /bin/sed 's/[^0-9]*\([0-9]\+\).*/\1/'`
if [ "$BATTERY" -le 15 ]
then
echo "SHUTTING DOWN -- LOW BATTERY"
/sbin/shutdown -h now
fi