1 2 3 4 5 6 7 8 9 10 11 12 13 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