Skip to content

Instantly share code, notes, and snippets.

@holys
Created October 29, 2012 13:40
Show Gist options
  • Save holys/3973614 to your computer and use it in GitHub Desktop.
Save holys/3973614 to your computer and use it in GitHub Desktop.
digest from https://bbs.archlinux.org/viewtopic.php?id=62286 ,run in cron mode , to check if it is low battery and then suspend
#!/bin/bash
battery='-';
bat_dir="/proc/acpi/battery/BAT0";
if [ -d "$bat_dir" ]; then
remaining="$(awk '/remaining capacity/ {print $3}' <${bat_dir}/state)"
total="$(awk '/last full capacity/ {print $4}' <${bat_dir}/info)"
battery_level="$((remaining *100 /total))"
battery="${battery_level}"
fi
if (( "${battery}" <= 5 )); then
/usr/sbin/pm-suspend
fi
echo "${battery}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment