Friday, December 20, 2013

Get Battery Status from Terminal

I wanted to trigger an application based on the current status of the battery, so I wanted to get the information about the current battery charge status.
Its fairly simple in Linux. 'acpi' is very handy for the purpose. If you haven't installed it yet (you can check it using the code below):

rpm -qa acpi
You can install it easily using apt-get in Ubuntu or if your machine is rpm based like mine, you can look for it in web.

For CentOS 6 users, the download link is here.

Here are some cool things you can do with acpi:

1. Check battey status


2. Check Battery Temperature

acpi -t

3. Check Battey Temperature ( in Fahrenheit )

acpi -t -f

4. Check power status

acpi -a

5. Show every device

acpi -V

Now that you have the information, you can play with it as you want. Here a simple bash script to get the battery information only:

battery=(${data//,/ })
echo ${battery[3]}

Enjoy :)


Post a Comment