I needed a little audible alarm to alert me when a laptop on the other side of the room or little device without display is running out of battery. Written on the run it’s nothing complex - all I need to know is when I’m under an hour so I can plug in.
You’re welcome.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #!/bin/bash
# Cute little audible alarm for low battery on GNU/Linux systems.
# Requires 'beep' and 'acpi'.
POLL=10
while true;
do
BAT=$(acpi)
if [[ "$BAT" == *Discharging* ]]
then
HOUR=$(echo $BAT | awk '{ print $5 }'| cut -d ':' -f 1)
if [[ "$HOUR" == "00" ]]
then
# Under an hour left
beep -l 100 -r 2 -l 100 -f 3000 -r 2 -n -l 100 -r 2 -f 2200
fi
fi
sleep $POLL
done
|