#!/usr/bin/perl # # tempmontk - Perl/Tk script to monitor CPU temperature from /proc/sensors # Version 1.0 - Sun Feb 21 08:24:29 CST 1999 # Copyright (C) 1999 Steven Pritchard # This script may be distributed under the same terms as Perl itself. use strict; use vars qw($mw $board $cpu $text $label $hot $defcolor $small $state); use Tk; $mw=MainWindow->new; $mw->title('Temperature monitor'); $mw->CmdLine(); $small=grep(/^-small$/, @ARGV); $defcolor=$mw->cget(-bg); $label=$mw->Label(-textvariable=>\$text)->pack(-expand=>1); &update; $mw->repeat(10000, \&update); MainLoop; sub chktemp { my($board,$cpu)=@_; open(SENSORS, ") { if (/^Mainboard:\s*([\d\.]+)/) { $$board=$1; } elsif (/^Temp-1:\s*([\+\d\.]+)/) { $$cpu=$1; } } close(SENSORS); } sub update { $text=chktemp(\$board, \$cpu); if ($small) { if ($state) { $text="Board:\n$board"; } else { $text="CPU:\n$cpu"; } $state=!$state; } else { $text="CPU: $cpu\nMainboard: $board"; } if ($cpu>49) { $hot=1; $mw->configure(-bg=>"red"); $label->configure(-bg=>"red"); $mw->bell(); } elsif ($cpu>44) { $hot=1; $mw->configure(-bg=>"yellow"); $label->configure(-bg=>"yellow"); } elsif ($hot) { $hot=0; $mw->configure(-bg=>$defcolor); $label->configure(-bg=>$defcolor); } }