All pastes #2099831 Raw Edit

Anonymous

public text v1 · immutable
#2099831 ·published 2012-01-05 21:02 UTC
rendered paste body
#!/bin/bash
     
#store current state on start
last_state=`cat /proc/acpi/battery/BAT1/state`

#lets write it to console
echo "current_state: $last_state"
     
#keep looking for changes using an infinite loop

while true
do

 state=`cat /proc/acpi/battery/BAT1/state`
 if [[ "$state" == "$last_state" ]];
 then
    echo "state not changed don't do anything"
 else
    echo "state changed to $state , do something now"
    #update last state
    last_state=`echo $state`
 fi
#just wait a little to avoid high cpu load
sleep 5
done