By putting all of these stuffs altogether, we will estimate how many power used by our lovely Ubuntu box.
# Make a shell script to cat voltage and ampere usage
#!/bin/bash# Make two variables to store voltage and ampere value
cat /proc/acpi/battery/C1AC/state | grep "present voltage" |
awk '{print $3}'
cat /proc/acpi/battery/C1AC/state | grep "present rate" |
awk '{print $3}'
volt=`cat /proc/acpi/battery/C1AC/state | grep "present voltage" |# Divide variable volt and ampere by 1000 because it still in mV or mA unit
awk '{print $3}'`
ampere=`cat /proc/acpi/battery/C1AC/state | grep "present rate" |
awk '{print $3}'`
volt=`echo "scale=3;$volt/1000"|bc`Parameter scale is used to set precision. If we set them to 3, then we will get three decimal places precision.
ampere=`echo "scale=3;$ampere/1000"|bc`
# Measure the power by simply multiply voltage and current consumed
power=`echo "scale=3;$v*$a"|bc`# And the full shell script is illustrated below:
#!/bin/bash# And it will give us a message like this:
volt=`cat /proc/acpi/battery/C1AC/state | grep "present voltage" |
awk '{print $3}'`
ampere=`cat /proc/acpi/battery/C1AC/state | grep "present rate" |
awk '{print $3}'`
volt=`echo "scale=3;$volt/1000"|bc`
ampere=`echo "scale=3;$ampere/1000"|bc`
echo "Present voltage: " $volt "Volt"
echo "Present current: " $ampere "Ampere"
power=`echo "scale=3;$volt*$ampere"|bc`
echo "Present power :" $power "Watt"
Present voltage: 16.285 Volt
Present current: 1.507 Ampere
Present power : 24.541 Watt
This shell script has been tested in Ubuntu Lucid Lynx 10.04 and it works well. Enjoy!
No comments:
Post a Comment