From a9d284811255a1982ff2587467a77a27a82dd74a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 30 Dec 2011 12:36:16 -0500 Subject: Create batterymon, a program that will monitor the battery, and run a command if discharging and below a certain percent. --- .gitignore | 1 + Makefile | 1 + batterymon.sh | 14 ++++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 batterymon.sh diff --git a/.gitignore b/.gitignore index 2962396..002ffda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *~ arg +batterymon chardiff chardiff_pre chardiff_post diff --git a/Makefile b/Makefile index 5a82eec..7365cbc 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ RM = rm -f BINFILES = \ arg \ + batterymon \ chardiff \ chardiff_pre \ chardiff_post \ diff --git a/batterymon.sh b/batterymon.sh new file mode 100644 index 0000000..6396c2d --- /dev/null +++ b/batterymon.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +thresh=$1 +shift + +while true; do + num=`acpi|sed -nr '/Discharging/s/.*, ([0-9]*)%,.*/\1/p'` + num=${num:-100} + if (( "$num" < "$thresh" )); then + eval "$*" + else + sleep 1 + fi +done -- cgit v1.2.3