Linux Shutdown on Low Battery
Jul 16, 2015

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.

#!/bin/bash
BATTERY=`/bin/upsc apc@localhost | /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
Comments