Advertisement
Guest User

monitorar_bateria

a guest
May 1st, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.83 KB | None | 0 0
  1. #!/bin/bash
  2. # Autor: Daemonio (Marcos Paulo Ferreira)
  3. # Contato: undefinido gmail com
  4. #
  5. # [monitorar_bateria.sh]
  6. # Script que lanca uma notificacao quando
  7. # a bateria estiver sendo usada.
  8. # Isso eh util para os lerdos como eu que
  9. # esquecem de ligar o notebook na tomada. :|
  10. #
  11. # Mon Mar 28 09:30:39 BRT 2011
  12. # Sun May  1 13:12:08 BRT 2011
  13. #
  14.  
  15. state_file='/proc/acpi/battery/BAT/state'
  16. info_file='/proc/acpi/battery/BAT/info'
  17. rate='0.9' # 90%
  18.  
  19. while :
  20. do
  21.     REMAINING=$(sed -n '/^remaining capacity:/s/[^0-9]//gp' $state_file)
  22.     LAST_FULL=$(sed -n '/^last full capacity:/s/[^0-9]//gp' $info_file)
  23.     RATE=$(echo "$LAST_FULL * $rate" | bc)
  24.    
  25.     if [ $REMAINING -lt ${RATE%.*} ] && grep -q 'discharging' $state_file
  26.     then
  27.         notify-send -u critical -t 5000 'A bateria esta sendo usada.'
  28.     fi
  29.  
  30.     sleep 500
  31. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement