From a36ecefba2a3d54feba3206e058df5c33aba4af9 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 3 Dec 2013 13:27:04 -0500 Subject: touch up {battery,temp}mon --- batterymon.sh | 21 +++++++++++++-------- tempmon.sh | 20 ++++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/batterymon.sh b/batterymon.sh index 6396c2d..34e7faa 100644 --- a/batterymon.sh +++ b/batterymon.sh @@ -1,14 +1,19 @@ #!/bin/bash +if [[ $# -ne 2 ]]; then + echo "Usage: $0 THRESHOLD COMMAND" +fi + thresh=$1 -shift +cmd=$2 + 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 + num=`acpi|sed -nr '/Discharging/s/.*, ([0-9]*)%,.*/\1/p'` + num=${num:-100} + if (( "$num" < "$thresh" )); then + eval "$cmd" + else + sleep 1 + fi done diff --git a/tempmon.sh b/tempmon.sh index 7fe99d9..3e752be 100644 --- a/tempmon.sh +++ b/tempmon.sh @@ -1,14 +1,18 @@ #!/bin/bash +if [[ $# -ne 2 ]]; then + echo "Usage: $0 THRESHOLD COMMAND" +fi + thresh=$1 -shift +cmd=$2 while true; do - num=`acpi -t|sed -nr 's/.*, ([0-9.]*) .*/\1/p` - num=${num:-0} - if (( "$num" > "$thresh" )); then - eval "$*" - else - sleep 1 - fi + num=`acpi -t|sed -nr 's/.*, ([0-9.]*) .*/\1/p` + num=${num:-0} + if (( "$num" > "$thresh" )); then + eval "$cmd" + else + sleep 1 + fi done -- cgit v1.2.3-2-g168b