diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-12-30 12:36:16 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-12-30 12:36:16 -0500 |
commit | a9d284811255a1982ff2587467a77a27a82dd74a (patch) | |
tree | 32992285f5722501a9581634f3c2f245dc4b3f7e | |
parent | e3f67d934025ba0c6853e8b8cdaddb97dbac1283 (diff) |
Create batterymon, a program that will monitor the battery, and run a command if discharging and below a certain percent.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | batterymon.sh | 14 |
3 files changed, 16 insertions, 0 deletions
@@ -1,5 +1,6 @@ *~ arg +batterymon chardiff chardiff_pre chardiff_post @@ -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 |