Originally published at Dom's Blog. You can comment here or there.
I often run applications on my laptop fullscreen, as I’ve mentioned before. Aside from a lastline configuration in screen, it is sometimes useful to be notified in a nice obvious manner when my laptop battery is getting low, so I created a bash script to use notify-send to display the percentage remaining on the battery when it is below a certain threshold.

There are two parts to this, the crontab entry which causes the script to be executed each minute, and the script itself, which obtains the value of the remaininng battery percentage, turns it into a bare number, and if it’s lower than a particular amount, it displays it.
Here’s the script code itself:
#!/bin/bash
percentage=$(yacpi -p | awk '{print $4}')
value=$(echo $percentage | sed -e 's/\%//')
if [ $value -lt 35 ] ; then notify-send -i battery "Battery $percentage" ; fi
In order to execute this each minute, edit the crontab with the command crontab -e and create a line with asterisks for each of the initial five fields describing which minute of which hour of which day in which month on which weekday it is to be run, followed by the path to the script; you can display the contents of your crontab with the -l option as shown here:
dominic@ubuntu-eee:~ $ crontab -l
# m h dom mon dow command
* * * * * DISPLAY=:0 /home/dominic/bin/gbattcheck
dominic@ubuntu-eee:~ $ cat bin/gbattcheck


