From Electron Cloud
Jump to: navigation, search
(Apple Intel systems)
(Lenovo S10-3t)
 
Line 102: Line 102:
 
</pre>
 
</pre>
  
==Lenovo S10-3t==
+
==Lenovo S10-3t, Thinkpad T61 etc.==
 
<pre>
 
<pre>
 
+
#!/bin/bash
#!/bin/sh
+
if [ -e /sys/class/power_supply/BAT? ]
CHARGE_NOW=`cat /sys/class/power_supply/BAT?/charge_now`
+
then
CHARGE_FULL=`cat /sys/class/power_supply/BAT?/charge_full`
+
        if [ -e /sys/class/power_supply/BAT?/energy_now ]
CHARGE_PERCENT=$(( $CHARGE_NOW * 100 / $CHARGE_FULL ))
+
        then
CHARGE_NOW=`cat /proc/acpi/battery/BAT?/state | grep remaining | cut -c26-`
+
                CHARGE_NOW=`cat /sys/class/power_supply/BAT?/energy_now`
CHARGE_FULL=`cat /proc/acpi/battery/BAT?/info | grep last | cut -c26-`
+
                CHARGE_FULL=`cat /sys/class/power_supply/BAT?/energy_full`
cat /proc/acpi/battery/BAT?/state | grep -v remaining
+
        fi
 +
        if [ -e /sys/class/power_supply/BAT?/charge_now ]
 +
        then
 +
                CHARGE_NOW=`cat /sys/class/power_supply/BAT?/charge_now`
 +
                CHARGE_FULL=`cat /sys/class/power_supply/BAT?/charge_full`
 +
        fi
 +
        CHARGE_PERCENT=$(( $CHARGE_NOW * 100 / $CHARGE_FULL ))
 +
        #CHARGE_NOW=`cat /proc/acpi/battery/BAT?/state | grep remaining | cut -c26-`
 +
        #CHARGE_FULL=`cat /proc/acpi/battery/BAT?/info | grep last | cut -c26-`
 
echo "Charge:                  $CHARGE_NOW / $CHARGE_FULL = $CHARGE_PERCENT%"
 
echo "Charge:                  $CHARGE_NOW / $CHARGE_FULL = $CHARGE_PERCENT%"
for s in `ls -d /sys/devices/virtual/thermal/thermal_zone*`
+
fi
 +
if [ -d /sys/devices/platform/coretemp.* ]
 +
then
 +
        for s in `ls -d /sys/devices/platform/coretemp.*/temp*_label`
 +
        do
 +
                echo "Temperature `cat $s`:      $((`cat ${s/label/input}` / 1000)) °C"
 +
        done
 +
fi
 +
for z in `ls -d /sys/devices/virtual/thermal/thermal_zone?`
 
do
 
do
         echo "Temperature `cat $s/type`:      $((`cat $s/temp` / 1000)) °C"
+
         for s in `ls -d $z`
 +
        do
 +
                echo "Temperature `cat $s/type`:      $((`cat $s/temp` / 1000)) °C"
 +
        done
 +
done
 +
for s in `ls -d /sys/devices/system/cpu/cpu?`
 +
do
 +
        echo "`basename $s`:                    $((`cat $s/cpufreq/scaling_cur_freq` / 1000)) MHz `cat $s/cpufreq/scaling_governor` from ( `cat $s/cpufreq/scaling_available_frequencies`)"
 
done
 
done
echo "Temperature `cat /sys/devices/platform/coretemp.0/temp1_label`:      $((`cat /sys/devices/platform/coretemp.0/temp1_input` / 1000)) °C"
 
 
</pre>
 
</pre>

Latest revision as of 06:14, 24 October 2012

This is a convention I wish somebody else had thought of and publicized widely a long time ago... there should be one memorable command to see the most relevant power and sensor info on every Linux box. My convention is to call this pow. It has to be implemented differently on different systems, although that could be automated in some kind of complicated "pow" package which noone has written, AFAIK.

For GUI purposes, gkrellm does a great job - it finds and understands the Apple SMC sensors just as well as the ACPI ones, looks slick, updates very smoothly and doesn't take much CPU. It's just that "pow" is nice to have for remote SSH sessions.

ACPI-compatible PCs

A shell alias might be good enough:

alias pow='cat /proc/acpi/battery/BAT1/info | grep last | cat - /proc/acpi/battery/BAT1/state /proc/acpi/thermal_zone/THRM/temperature'

or you could use a script:

#!/bin/sh
CHARGE_NOW=`cat /sys/class/power_supply/BAT0/charge_now`
CHARGE_FULL=`cat /sys/class/power_supply/BAT0/charge_full`
CHARGE_PERCENT=$(( $CHARGE_NOW * 100 / $CHARGE_FULL ))
CHARGE_NOW=`cat /proc/acpi/battery/BAT0/state | grep remaining | cut -c26-`
CHARGE_FULL=`cat /proc/acpi/battery/BAT0/info | grep last | cut -c26-`
cat /proc/acpi/battery/BAT0/state | grep -v remaining
echo "Charge:                    $CHARGE_NOW / $CHARGE_FULL = $CHARGE_PERCENT%"
cat /proc/acpi/thermal_zone/TZS0/temperature /proc/acpi/thermal_zone/TZS1/temperature

which produces output like this:

[acer][02:10:26 PM] pow
present:                 yes
capacity state:          ok
charging state:          charging
present rate:            2200 mA
present voltage:         11663 mV
Charge:	           1606 mAh / 3799 mAh = 42%
temperature:             45 C
temperature:             48 C

Apple Intel systems

Apple uses SMC (system management whatchamacallit) rather than ACPI. If your Linux kernel has support for that, there will be some nodes under /sys/devices/platform/applesmc.768 on a mac mini; not sure if the 768 is different on other systems, or what. Here's another crude script (which would be better at least re-written in python or something, because running multiple "cut" subprocesses is inefficient and brittle):

#!/bin/sh
for s in `ls /sys/devices/platform/applesmc.*/temp*`
do
        integer=`cat $s | cut -c1-2`
        fraction=`cat $s | cut -c3-5`
        echo "temperature:               $integer.$fraction °C"
done
for s in `ls /sys/devices/platform/applesmc.*/fan*output`
do
        partial_path=`echo $s | cut -d'_' -f1`
        name=`echo $partial_path | cut -d'/' -f6`
        current=`cat $s`
        min=`cat ${partial_path}_min`
        max=`cat ${partial_path}_max`
        echo "$name:                      $current RPM (range $min - $max)"
done
for s in `ls /dev/sd?`
do
        hddtemp $s 2>/dev/null
done

and its output looks like this:

[mini][03:46:57 PM] pow
temperature:               59.250 °C
temperature:               56.000 °C
fan1:                      1610 RPM (range 1000 - 5500)
/dev/sda: ST9500420AS:  52°C or °F

The above is getting outdated. Here's one that works on a Macbook Pro as of mid-2012:

#!/bin/sh
CHARGE_NOW=`cat /sys/class/power_supply/BAT0/energy_now`
CHARGE_FULL=`cat /sys/class/power_supply/BAT0/energy_full`
CHARGE_PERCENT=$(( $CHARGE_NOW * 100 / $CHARGE_FULL ))
echo "Battery status:            `cat /sys/class/power_supply/BAT0/status`"
echo "Charge:                    $CHARGE_NOW / $CHARGE_FULL = $CHARGE_PERCENT%"
for s in `ls /sys/devices/platform/applesmc.*/temp*input`
do
        integer=`cat $s | cut -c1-2`
        fraction=`cat $s | cut -c3-5`
	labelname=${s%input}label
        echo "`cat $labelname`:                      $integer.$fraction °C"
done
for s in `ls /sys/devices/platform/applesmc.*/fan*output`
do
        partial_path=`echo $s | cut -d'_' -f1`
        name=`echo $partial_path | cut -d'/' -f6`
        current=`cat $s`
        min=`cat ${partial_path}_min`
        max=`cat ${partial_path}_max`
        echo "$name:                      $current RPM (range $min - $max)"
done
# assumes hddtemp is running as a daemon on this port
netcat localhost 7634

Lenovo S10-3t, Thinkpad T61 etc.

#!/bin/bash
if [ -e /sys/class/power_supply/BAT? ]
then
        if [ -e /sys/class/power_supply/BAT?/energy_now ]
        then
                CHARGE_NOW=`cat /sys/class/power_supply/BAT?/energy_now`
                CHARGE_FULL=`cat /sys/class/power_supply/BAT?/energy_full`
        fi
        if [ -e /sys/class/power_supply/BAT?/charge_now ]
        then
                CHARGE_NOW=`cat /sys/class/power_supply/BAT?/charge_now`
                CHARGE_FULL=`cat /sys/class/power_supply/BAT?/charge_full`
        fi
        CHARGE_PERCENT=$(( $CHARGE_NOW * 100 / $CHARGE_FULL ))
        #CHARGE_NOW=`cat /proc/acpi/battery/BAT?/state | grep remaining | cut -c26-`
        #CHARGE_FULL=`cat /proc/acpi/battery/BAT?/info | grep last | cut -c26-`
echo "Charge:                  $CHARGE_NOW / $CHARGE_FULL = $CHARGE_PERCENT%"
fi
if [ -d /sys/devices/platform/coretemp.* ]
then
        for s in `ls -d /sys/devices/platform/coretemp.*/temp*_label`
        do
                echo "Temperature `cat $s`:      $((`cat ${s/label/input}` / 1000)) °C"
        done
fi
for z in `ls -d /sys/devices/virtual/thermal/thermal_zone?`
do
        for s in `ls -d $z`
        do
                echo "Temperature `cat $s/type`:      $((`cat $s/temp` / 1000)) °C"
        done
done
for s in `ls -d /sys/devices/system/cpu/cpu?`
do
        echo "`basename $s`:                    $((`cat $s/cpufreq/scaling_cur_freq` / 1000)) MHz `cat $s/cpufreq/scaling_governor` from ( `cat $s/cpufreq/scaling_available_frequencies`)"
done