summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2011-12-30 12:36:16 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2011-12-30 12:36:16 -0500
commita9d284811255a1982ff2587467a77a27a82dd74a (patch)
tree32992285f5722501a9581634f3c2f245dc4b3f7e
parente3f67d934025ba0c6853e8b8cdaddb97dbac1283 (diff)
Create batterymon, a program that will monitor the battery, and run a command if discharging and below a certain percent.
-rw-r--r--.gitignore1
-rw-r--r--Makefile1
-rw-r--r--batterymon.sh14
3 files changed, 16 insertions, 0 deletions
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