Advertisement
Alie

powersave

Sep 11th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.88 KB | None | 0 0
  1. #!/bin/bash
  2. _BAT_STATUS=$(acpitool | grep Battery | gawk '{print $4}' | sed -e 's/,//g')
  3. #_BAT_TIME=$(acpitool | grep Battery | gawk '{print $6}' | sed -e 's/://g' | sed -e 's/^0*//')
  4. _BAT_PERCENT=$(acpitool | grep Battery | gawk '{print $5}' | sed -e 's/,//g' -e 's/%//g' -e 's/\.//g')
  5.  
  6. # test area
  7.  
  8. #echo "_BAT_STATUS: $_BAT_STATUS \n _BAT_TIME: $_BAT_TIME"
  9.  
  10. while [ "$_BAT_STATUS" == "discharging" ]
  11. do
  12.  
  13.         if [[ "$_BAT_PERCENT" -ge 1000 ]];
  14.         then
  15.                 exit
  16.         elif [[ "$_BAT_PERCENT" -ge 700 && "$_BAT_PERCENT" -lt 999 ]];
  17.         then
  18.                  DISPLAY=:0 sudo -u alie notify-send "Information" "Low power detected" -i /usr/share/icons/hicolor/32x32/actions/Alert-icon.png
  19.                 sleep 40
  20.                 if [ `acpitool | grep Battery | gawk '{print $4}' | sed -e 's/,//g'` == "discharging" ];
  21.                 then
  22.                         shutdown -h now
  23.                 else
  24.                         exit
  25.                 fi
  26.         elif [[ "$_BAT_PERCENT" -lt 700 ]];
  27.         then
  28.                 shutdown -h now
  29.         else
  30.                 exit
  31. fi
  32.  
  33. ######Energy monitor block
  34. #       if [[ "$_BAT_TIME" -le 1000000 && "$_BAT_TIME" -ge 160 ]];
  35. #       then
  36. #               exit
  37. #       elif [[ "$_BAT_TIME" -le 160 && "$_BAT_TIME" -ge 132 ]];
  38. #       then
  39. #               DISPLAY=:0 sudo -u alie notify-send "Information" "Low power detected" -i /usr/share/icons/hicolor/32x32/actions/Alert-icon.png
  40. #               sleep 40
  41. #               if [ `acpitool | grep Battery | gawk '{print $4}' | sed -e 's/,//g'` == "discharging" ];
  42. #               then
  43. #                       shutdown -h now
  44. #               else
  45. #                       exit
  46. #               fi
  47. #       elif [ "$_BAT_TIME" -lt 132 ];
  48. #       then
  49. #               shutdown -h now
  50. #       else
  51. #               exit
  52. #       fi
  53. ########
  54.        exit
  55. done
  56. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement