LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-03-2013, 10:32 AM   #1
stozi
Member
 
Registered: Mar 2010
Distribution: Void Linux
Posts: 39

Rep: Reputation: 0
So close to getting battery % with awk


Dear sirs,

At present I have something that looks like this:
Code:
#!/bin/sh

now=`cat /sys/class/power_supply/BAT0/charge_now`
full=`cat /sys/class/power_supply/BAT0/charge_full`
out=`echo $now $full | awk '{ printf("%f\n", $1/$2) }'`
echo "Charge: "$out"%"
this math is wrong, outputing "Charge: 0.932519%" but the correct value is 100 times that.

How can I edit that to give me the correct value?

Thanks very much!
 
Old 09-03-2013, 10:36 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326

Rep: Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920
this worx for me:
Code:
#!/bin/sh

now=`cat /sys/class/power_supply/BAT0/charge_now`
full=`cat /sys/class/power_supply/BAT0/charge_full`
out=`echo $now $full | awk '{ printf("%f\n", $1/$2 * 100) }'`
echo "Charge: "$out"%"
 
Old 09-03-2013, 12:08 PM   #3
stozi
Member
 
Registered: Mar 2010
Distribution: Void Linux
Posts: 39

Original Poster
Rep: Reputation: 0
You sir are a genius.
 
Old 09-03-2013, 12:13 PM   #4
itlb
LQ Newbie
 
Registered: Aug 2013
Distribution: Debian
Posts: 29

Rep: Reputation: Disabled
So close to getting battery % with awk

the 'acpi' command also gives battery status on my Debian laptop.
 
Old 09-03-2013, 05:13 PM   #5
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by itlb View Post
the 'acpi' command also gives battery status on my Debian laptop.
yup and performs without a headache to perform any calculations.
 
Old 09-04-2013, 09:16 AM   #6
stozi
Member
 
Registered: Mar 2010
Distribution: Void Linux
Posts: 39

Original Poster
Rep: Reputation: 0
Thanks, I know, may be helpful for anyone else who views this, I wanted to figure out how to do without.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Battery settings are stored in system or the battery firmware? aranwe Linux - Laptop and Netbook 4 12-21-2012 03:33 PM
Battery applet/battery monitor problem on Dell Studio lnx Linux - Laptop and Netbook 8 03-28-2011 04:40 AM
LXer: Battery Status 0.1 Released - Improved Battery Applet For The Gnome Desktop LXer Syndicated Linux News 0 05-21-2010 07:30 PM
System hangs when I close lid, put battery in etc wet Linux - Newbie 1 10-10-2007 01:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration