#!/usr/bin/perl5 # usage: mrtg-getinfo-therm [ -l ] # # -l get low thermostat setting # default is to get the high thermostat setting # # Only test on Rev 5 boards. # # This script polls information from some /proc files and outputs the polled # information in a format usable by mrtg. It can also function as a required # file, in which case it will gather the data from /proc but not output # anything to stdout. # # $Header: /u/acli/Projects/netwinder.org/scripts/RCS/mrtg-getinfo-therm,v 1.1 1998/11/22 23:43:52 acli Exp $ open(THERM, "/proc/therm") || die("/proc/therm: $!\nstopped"); while () { if (/^Therm.*: [^-\d]*([-\d\.]+)([^-\d]*([-\d\.]+))?.*temp.*: ([-\d\.]+).*(fan (\w+))?/i) { ($hi, $lo, $temp, $fan) = ($1, $3, $4, $6 eq "ON"); } } close(THERM); open(UPTIME, "/proc/uptime") || die("/proc/uptime: $!\nstopped"); =~ /^(\d+)/; $uptime = $1; close(UPTIME); open(HOSTNAME, "/proc/sys/kernel/hostname") || die("/proc/sys/kernel/hostname: $ !\nstopped"); $hostname = ; chomp $hostname; close(HOSTNAME); # See if we are being require'd from another perl5 program. # If we are, we expect caller(0) to return non-null information; # in particular, $subroutine should be "(eval)" (by empirical observation). ($package, $filename, $line, $subroutine, $hasargs, $wantargs) = caller(0); if (! defined $subroutine) { require 'getopts.pl'; Getopts("hl"); if ($opt_l) { printf("%d\n%d\n", $lo, $temp); } else { printf("%d\n%d\n", $hi, $temp); } if ($uptime >= 86400) { my($days) = int($uptime/86400); printf("%d day%s, ", $days, $days == 1? "": "s"); } printf("%02d:%02d:%02d\n", ($uptime/3600)%24, ($uptime/60)%60, $uptime%60); printf("%s\n", $hostname); } 1;