Advertisement
Alie

powersave_cron

Jun 29th, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.08 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # environment variables
  4.  
  5. #export DISPLAY =:0.0
  6.  
  7. # variables
  8.  
  9. _BAT_STATUS=$(acpitool | grep Battery | gawk '{print $4}' | sed -e 's/,//g')
  10. _BAT_TIME=$(acpitool | grep Battery | gawk '{print $6}' | sed -e 's/://g' | sed -e 's/^0*//')
  11. # test area
  12.  
  13. #echo "_BAT_STATUS: $_BAT_STATUS \n _BAT_TIME: $_BAT_TIME"
  14.  
  15. while [ "$_BAT_STATUS" == "discharging" ]
  16. do
  17.         if [[ "$_BAT_TIME" -le 1000000 && "$_BAT_TIME" -ge 1000 ]];
  18.         then
  19.                 exit
  20.         elif [[ "$_BAT_TIME" -le 1000 && "$_BAT_TIME" -ge 500 ]];
  21.         then
  22.                 notify-send "Information" "Low power detected" -i /usr/share/icons/hicolor/32x32/actions/Alert-icon.png
  23.                 sleep 40
  24.                 if [ `acpitool | grep Battery | gawk '{print $4}' | sed -e 's/,//g'` == "discharging" ];
  25.                 then
  26.  
  27.                         shutdown -h now
  28.                 else
  29.                         exit
  30.                 fi
  31.         elif [ "$_BAT_TIME" -lt 500 ];
  32.         then
  33.                 shutdown -h now
  34.         else
  35.                 exit
  36.         fi
  37. exit
  38. done
  39. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement