#!/usr/bin/perl -w use strict; my $action = shift; system("killall -q osd_cat > /dev/null 2>&1"); if ( $action eq "info" ) { my $thrm = "/proc/acpi/thermal_zone/THRM"; my $fan = "/proc/acpi/fan"; my $power = "/proc/acpi/processor"; my $freq = "/sys/devices/system/cpu/cpu0/cpufreq"; my $state = ""; my $t; $t = cat("$power/CPU0/power"); if ( $t =~ /^active state:\s+(\S+)/m ) { my $s = $1; $state .= "CPU state: $1"; $state .= " [$1]" if $t =~ /\s\*?$s:\s+type\[(.*?)\]/m; } if ( cat("$freq/scaling_cur_freq") =~ /^(\d+)00000$/ ) { my $mhz = $1; if ( $mhz > 10 ) { $mhz =~ s/^(\d)(\d).*/$1.$2/; $state .= " @ $mhz Ghz"; } else { $state .= " @ ${mhz}00 Mhz"; } } $state .= "\n" if $state; if ( cat("$thrm/temperature") =~ /(\d+) C/ ) { $state .= "Temperature: $1°C\n"; } if ( $t = cat("$thrm/state") ) { $t =~ s/\s+/ /g; $state .= ucfirst($t) . "\n"; } if ( $t = cat("$thrm/cooling_mode") ) { $t =~ s/\s+/ /g; $state .= ucfirst($t) . "\n"; } my $fanstate = ""; foreach ( glob("$fan/FAN?/state") ) { if ( ($t = cat($_)) =~ /status:\s+(.*)/ ) { $fanstate = "Fan status: " unless $fanstate; $fanstate .= "$1 "; } } chop($fanstate); $state .= "$fanstate\n" if $fanstate; if ( $ENV{DISPLAY} ) { xosd($state); } else { warn($state); } } sub xosd { my ($info) = @_; open(XOSD, "|xosd --lines=5 --delay=4 -- -"); print XOSD $info; close(XOSD); } sub cat { my $file = shift; local($/) = undef; my $ret = ""; my $cat; open($cat, $file) and $ret = <$cat> and close($cat); $ret; } # =head1 AUTHOR # # Johan Vromans # # =head1 COPYRIGHT AND DISCLAIMER # # This program is Copyright 2004,2005 by Johan Vromans. # This program is free software; you can redistribute it and/or # modify it under the terms of the Perl Artistic License or the # GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or (at your option) any # later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # If you do not have a copy of the GNU General Public License write to # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, # MA 02139, USA.