I'm using Ubuntu, but I have i3 as my window manager instead of a desktop environment.
When my battery reaches 0%, the computer will just abruptly shut down, no warning or anything.
Is there a simple script or configuration I can set up so that it goes to sleep at, say 4% battery?
Best Answer
Here's a small script that checks for the battery level and calls a custom command, here
pm-hibernate
, in case the battery level is below a certain threshold.It's a very simple script, but I think you get the idea and can easily adapt it to your needs. The path to the battery level might be different on your system. A little more portable would probably be to use something like
acpi | cut -f2 -d,
to obtain the battery level. This script can be scheduled by cron to run every minute. Edit your crontab withcrontab -e
and add the script:Another solution would be to install a desktop environment like Gnome or Xfce (and change your window manager to i3). Both mentioned destop environments feature power management daemons which take care of powering off the computer. But I assume you deliberately don't use them and are seeking for a more minimalistic solution.