Battery Power

Hi ALL;

How can I setup, like my laptop is using battery, if the power was lower than 20%, and the computer will shutdown?
 
You can run a shell script either via cron or just adding a loop with sleep in the script itself, e.g.:
Code:
#!/usr/local/bin/bash

CRITICAL=20
STATCMD='acpiconf -i 0'
LOOPDEL=30

while true
do
  REMCAP=`$STATCMD | sed -n 's/Remaining\ capacity:[^0-9]*\([0-9]*\)[^0-9]*/\1/p'`
  if [ $REMCAP -le $CRITICAL ]
  then
    <halt or suspend command>
  fi
  sleep $LOOPDEL
done
 
Code:
set -- `sysctl -n hw.acpi.acline hw.acpi.battery.life`

This would get remaining capacity (or empty string) to $2. What happens when there are two batteries ? I've always have just one.

Juha
 
If I were you, I'd run a cron job that spat out a desktop notification (via notify-send) reminding me to check my battery life every ten minutes. I refuse to believe anyone actually appreciates having their computer shut off when they're in the middle of doing something.
 
If I were you, I'd run a cron job that spat out a desktop notification (via notify-send) reminding me to check my battery life every ten minutes. I refuse to believe anyone actually appreciates having their computer shut off when they're in the middle of doing something.
You could suspend instead of shutting it down
 
You can run a shell script either via cron or just adding a loop with sleep in the script itself, e.g.:
Code:
#!/usr/local/bin/bash

CRITICAL=20
STATCMD='acpiconf -i 0'
LOOPDEL=30

while true
do
  REMCAP=`$STATCMD | sed -n 's/Remaining\ capacity:[^0-9]*\([0-9]*\)[^0-9]*/\1/p'`
  if [ $REMCAP -le $CRITICAL ]
  then
    <halt or suspend command>
  fi
  sleep $LOOPDEL
done
How can I setup a cron job to use your script?
 
You could suspend instead of shutting it down

The machine still "shuts off." Your work will be interrupted--no matter which command you run, your mindless machine gets to decide when you're done working. Get into the habit of actually checking your battery life, so you're not cut off in the middle of something important.

I guess my real point is that people who find this "feature" useful probably are just using their computers to kill time anyway, since they don't seem to actually care how much of it they have left. If you cared, you wouldn't be turning off your brain and letting the machine tell you when you're done.

How can I setup a cron job to use your script?

Read the relevant section of the FreeBSD Handbook and Google "cron job." Cron has been around for over forty years--information's not scant.
 
Maybe you would be interested of doing like I did for my laptop.

Laptop checks during boot if there is no acline available.
If so, it starts script that monitors battery capacity.
Script also monitors acline and exits if it comes on.
When capacity drops below threshold value, it gives loud warning to either turn acline on or it will shutdown the machine after safety period.

If acline is on during boot, script will not be started by boot process. However, devd(8) starts the script if acline is lost.
 
Back
Top