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.

#!/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
Comments