Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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:

/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0/capacity

I created the bash script:

!/bin/bash

load=$(cat /sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0/capacity) min_load=20 if [ $load <= min_load ]; then pm-suspend fi 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

1 Answer 1

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:

#!/bin/bash

load=$(cat /proc/acpi/battery)
min_load=20
if [ $load <= min_load ]; then
    pm-suspend
fi

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

Your Answer

 
discard

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.