|
|
发表于 2007-8-13 11:52:09
|
显示全部楼层
这是我显示CPU\风扇\电池的配置
cpu1 ${exec echo $(cat /sys/class/hwmon/hwmon1/device/temp1_input) / 1000 | bc}°C
风扇转速$alignr${exec echo $(cat /proc/acpi/ibm/fan |grep -Po [0-9+])} /分钟
电池:${exec battery_charge.pl}$alignr${exec battery_check.pl}
${execbar (exec battery_check.pl)}
电池状态的文件内容稍微复杂,我写了一个小perl程序, 放到了 /usr/bin/中
@localhost ~ $ cat /usr/bin/battery_charge.pl
#!/usr/bin/perl
#test mode match
$state_battery = undef;
open STATE, " <", "/proc/acpi/battery/BAT0/state";
while (<STATE>) {
chomp;
if (/charging state:\s+(.*)/) {
$state_battery = $1;
last;
}
}
print "$state_battery";
@localhost ~ $ cat /usr/bin/battery_check.pl
#!/usr/bin/perl
#test mode match
#
$remaining_capacity = undef;
$total_capacity = undef;
open STATE, " <", "/proc/acpi/battery/BAT0/state";
while (<STATE>) {
chomp;
if (/remaining capacity:\s+(\d+)/) {
$remaining_capacity = $1;
}
}
open INFO, " <", "/proc/acpi/battery/BAT0/info";
while (<INFO>) {
chomp;
if (/design capacity:\s+(\d+)/) {
$total_capacity = $1;
}
}
if ($total_capacity == 0) {
print "没有安装电池";
} else {
printf "%2.2f %", $remaining_capacity/$total_capacity*100;
} |
|