Monday, October 19, 2009

Low Battery Warning Beep Script For Linux

#!/bin/bash

DIR="/sys/class/power_supply/BAT0"
STATUS=$(cat "$DIR/status")

if [ "$STATUS" == "Discharging" ]
then
        WARN=$(cat "$DIR/alarm")
        for PREFIX in "charge" "energy"
        do
                if [ -f "$DIR/${PREFIX}_now" ]
                then
                        REMAIN=$(cat "$DIR/${PREFIX}_now")
                        if [ $REMAIN -le $WARN ]
                        then
                                mplayer /usr/share/sounds/bark.ogg
                        fi
                        break
                fi
        done
fi
Put that in your crontab and smoke it.

0 comments: