#!/bin/bash while true do state=`cat /proc/acpi/battery/BAT1/state` if [[ "$state" == "whatever" ]]; then echo "email" |mail -s "dhsudia" me@email else fi done # ----------------------------------------------------------------------------------------------------------------------------------------------------- #!/bin/bash # This will only do something if the state changes, and never exit. Start this in the background after adding your own actions for the change events last_state=`cat /proc/acpi/battery/BAT1/state` echo "current_state: $last_state" 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 $last_state , do something" last_state=`echo $state` fi sleep 5 done # ----------------------------------------------------------------------------------------------------------------------------------------------------- #!/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 # ----------------------------------------------------------------------------------------------------------------------------------------------------- cp /etc/pam_ldap.conf{,.old} # or even better: cp /etc/pam_ldap.conf{,.$(date +%F)}