pastebin - collaborative debugging tool
linux.kpaste.net RSS


Bash scriptu
Posted by Anonymous on Wed 25th Jan 2012 02:29
raw | new post

  1. #!/bin/bash
  2.  
  3. while true
  4. do
  5. state=`cat /proc/acpi/battery/BAT1/state`
  6. if [[ "$state" == "whatever" ]];
  7. then
  8. echo "email" |mail -s "dhsudia" me@email
  9. else
  10. fi
  11. done
  12.  
  13. # -----------------------------------------------------------------------------------------------------------------------------------------------------
  14.  
  15. #!/bin/bash
  16.  
  17. # 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
  18.  
  19.  
  20. last_state=`cat /proc/acpi/battery/BAT1/state`
  21. echo "current_state: $last_state"
  22.  
  23. while true
  24. do
  25. state=`cat /proc/acpi/battery/BAT1/state`
  26. if [[ "$state" == "$last_state" ]];
  27. then
  28.     echo "state not changed don't do anything"
  29. else
  30.     echo "state changed to $last_state , do something"
  31.    
  32.     last_state=`echo $state`
  33. fi
  34.  
  35. sleep 5
  36. done
  37.  
  38. # -----------------------------------------------------------------------------------------------------------------------------------------------------
  39.  
  40.  
  41. #!/bin/bash
  42.      
  43. #store current state on start
  44. last_state=`cat /proc/acpi/battery/BAT1/state`
  45.  
  46. #lets write it to console
  47. echo "current_state: $last_state"
  48.      
  49. #keep looking for changes using an infinite loop
  50.  
  51. while true
  52. do
  53.  
  54.  state=`cat /proc/acpi/battery/BAT1/state`
  55.  if [[ "$state" == "$last_state" ]];
  56.  then
  57.     echo "state not changed don't do anything"
  58.  else
  59.     echo "state changed to $state , do something now"
  60.     #update last state
  61.     last_state=`echo $state`
  62.  fi
  63. #just wait a little to avoid high cpu load
  64. sleep 5
  65. done
  66.  
  67.  
  68. # -----------------------------------------------------------------------------------------------------------------------------------------------------
  69.  
  70.  
  71. cp /etc/pam_ldap.conf{,.old}
  72.  
  73. # or even better:
  74.  
  75. cp /etc/pam_ldap.conf{,.$(date +%F)}

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at