summaryrefslogtreecommitdiff
path: root/batterymon.sh
blob: f46060c6799b9e5482d132d32496b90626825007 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
# Copyright (C) 2011, 2013 Luke Shumaker <lukeshu@sbcglobal.net>

if [[ $# -ne 2 ]]; then
	echo "Usage: $0 THRESHOLD COMMAND"
fi

thresh=$1
cmd=$2

while true; do
	num=`acpi|sed -nr '/Discharging/s/.*, ([0-9]*)%,.*/\1/p'`
	num=${num:-100}
	if (( "$num" < "$thresh" )); then
		eval "$cmd"
	else
		sleep 1
	fi
done