Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to control for setting my battery at a certain capacity (for ex.20%) then the laptop will be automatically standby or hibernate for long-lasting the battery. Is there any solution, please? Be noted: my Vostrol 3450, ubuntu 13.04, hibernate function is already rehabilitated.

The battery capacity I can find is in the file capacity as below:


I created the bash script:


load=$(cat /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0/capacity)
if [ $load <= min_load ]; then

On terminal, I perform the cli for test:

sudo /bin/battery-suspend

Then the result failed showing:

/bin/battery-suspend: line 5: =: No such file or directory
share|improve this question

The battery capacity is stored somewhere in /proc. Possibly /proc/acpi/battery or something like that. You could write a bash script that reads the battery status and issues a hibernate or suspend command. It would look something like this:


load=$(cat /proc/acpi/battery)
if [ $load <= min_load ]; then

I give no guarantee that this is right since I don't know how the output of cat /proc/acpi/battery looks like and I'm not that big of an bash script expert. Try it out and ask if you have any problems.

You could then create a cronjob that runs the script every minute or so. Take a look at this tutorial for cronjobs. You want to create your job as root user.

share|improve this answer
I tried to perform, but it's failed: "cat: /proc/acpi/battery: No such file or directory", What can I do for next? – evergreen May 13 '13 at 10:08
Like I said it's only possibly /proc/acpi/battery. Take a look into your /proc directory and try to find the file containing your battery status. There is really no default solution for this. You could use acpi -V (possibly install it first with sudo apt-get install acpi) but then you'd have to parse the output for the capacity. – André Stannek May 13 '13 at 11:05
What I can find described as above, hope it the right one. Could you help for creating a right bash script? – evergreen May 13 '13 at 17:13

You can try to use this script.

It raise a notification and then suspend your PC when battery level reach selected value.

#! /bin/bash

# read battery percentage value
OUT=`upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep percentage`

# select only the int value
IFS=':' read -ra P <<< "$OUT"

# send a notification and then suspend pc
# if battery level is under 20%
if (( $BATTERY_VALUE  <= "20")); then
  notify-send "Battery Low level! Your PC will be suspended!"

  # play sound if you want to be alerted
  # paplay /usr/share/sounds/freedesktop/stereo/complete.oga

  # wait for 3 seconds before suspend pc
  sleep 3
  # suspend your pc

Copy this script into a bash file and move it into local bin folder:

sudo mv <script_file> /usr/local/bin/

Where script_file is the name (or path) of your script. Then you can use cron daemon to run it every 5 minutes (or select your execution frequency) to check battery level. So edit cron as superuser (script need super user permission to suspend PC):

sudo crontab -e

Select preferred editor and add at the end of file this line:

*/5 * * * * /usr/local/bin/<script_file>

Change script_file with your script name.

Now it should work. Check it after a system reboot.

I hope this will help you.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.