#!/bin/sh #Company: PowerCraft Technology #Author: Copyright Jelle de Jong #Note: Please send me an email if you enhanced this script #System: Ubuntu/Debian GNU/Linux # Did the script work for you? # Yes # Yes, but with some errors # Yes, but I had to change some things # Not at all # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. #~ cat /sys/bus/acpi/devices/PNP0C0A\:00/power_supply\:BAT0/uevent #~ cat /sys/class/power_supply/BAT0/charge_now #~ lshal | grep battery #~ xmessage "I'll shut down in 4 minutes unless you connect to AC" & if grep -q Full /sys/class/power_supply/BAT0/status then # close this script, is it not nessesary when battery is not used exit fi while true do sleep 120 if grep -q Discharging /sys/class/power_supply/BAT0/status then if [ $(cat /sys/class/power_supply/BAT0/charge_now) -le 10000 ] then zenity --warning --text="I'll shut down in 3 minutes unless you connect to AC power" & sleep 180 if grep -q Discharging /sys/class/power_supply/BAT0/status then sudo shutdown -h now fi fi fi done exit #~ if ! grep -q on-line /proc/acpi/ac_adapter/AC0/state ; then #~ BAT_DIR=/proc/acpi/battery/BAT0 #~ FULL_BAT=`grep 'last full capacity' ${BAT_DIR}/info | awk '{ print $4 }'` #~ CUR_BAT=`grep 'remaining capacity' ${BAT_DIR}/state | awk '{ print $3 }'` #~ AVG=`expr $(expr ${CUR_BAT} \* 100) / ${FULL_BAT}` #~ #~ if [ "$AVG" -le "20" ]; then #~ xmessage Warning, Low Battery... $AVG & #~ fi #~ if [ "$AVG" -le "10" ]; then #~ xmessage "I'll shut down in 2 minutes unless you connect to AC." & #~ sleep 120 #~ if ! grep -q on-line /proc/acpi/ac_adapter/AC0/state ; then #~ sudo shutdown -h now #~ fi #~ fi #~ fi