ISSUE ===== I wanted some guidance on writing a script to monitor temperatures or my 11 or so Solaris boxes. I wanted crontab to mail me once a day with information. THANKS ====== My sincere thanks go to :- Christopher L. Barnard Michael Kalus Michael Wilkinson Josh Glover Albert White Glenn W Cantello Benjamin Ritcey Damir Delija Claude Charest Who shared useful scripts, advice and URLs of interest. OUTCOME ======= Plenty of scripts to play with and test, which is what I'm doing, thanks guys :-) CONTRIBUTIONS ============= From: Christopher L. Barnard <cbar44@tsg.cbot.com> that is exactly what I do. I put this script in /usr/local/bin and call it from cron every ten minutes. No problem -- no output. -----8<------ #!/usr/local/bin/perl # ### ### This script runs the 'prtdiag' utility and checks the temperature ### of all components. If it is too high, it prints output; if the temp ### is ok then it is silent. ### ### ### what to look for in the prtdiag -v output. Remember that the string ### specified in the $lookfor variable must be AT THE BEGINNING. This script ### will do a pattern match on the specified string, but the string here MUST ### start with character 1. ### $lookfor = "System Temperature"; ### ### when looking for $lookfor, this is the string to look for to ### end the given section. Remember that the string specified in the ### $looktoend variable must be AT THE BEGINNING. This script will do ### a pattern match on the specified string, but the string here MUST ### start with character 1. ### $looktoend = "===="; ### ### this is the temperature in celcius. If the temperature of any component ### is above this value, give all of the component temperatures. If all ### temperatures are below this threshold, exit silently. ### $tempmax=40; ### ### first check to see if the prtdiag binary exists. On older platforms, ### it will not. ### $uname = `uname -i`; chop $uname; $prtdiag="/usr/platform/$uname/sbin/prtdiag"; if (!(-e $prtdiag)) { printf("The file $prtdiag does not appear to exist.\n"); printf("aborting.\n"); exit 1; } ### ### ok, it exists, so run it and fill the "prtdiagout" array with the ### output. Put one line of output in each line of the array. ### @prtdiagout = `$prtdiag -v`; ### ### how many lines did the prtdiag command generate? ### $nolines = @prtdiagout; ### ### now go through the prtdiagout array selecting $lookfor and all lines ### after it until $looktoend is found. ### $tempfound = "0"; $j = 0; for ($i=0; $i<$nolines; $i++) { if ($tempfound == "1") { @results[$j] = @prtdiagout[$i]; $j++; $pos = -1; $pos = index(@prtdiagout[$i], $looktoend); if ( $pos == 0 ){ $tempfound = "2"; } } $pos = -1; $pos = index(@prtdiagout[$i], $lookfor); if ( $pos == 0 ) { $tempfound = "1"; @results[$j] = @prtdiagout[$i]; $j++; } } ### ### The $lookfor string was not found. Tell the user and exit. ### if ($tempfound eq "0") { printf("The string '$lookfor'\n"); printf("was not found in the output of '$prtdiag'.\n\n"); exit 1; } ### ### The $lookfor string was found, so the "results" array has been filled. ### go through that array, seeing if the second parameter is larger than the ### specified threshold, $maxtemp. Not all lines will have a number as their ### second element, but that is ok. ### $overtemp = "FALSE"; for ($i=0; $i<$j; $i++) { @fields = split(/[ \t]+/,@results[$i]); if (@fields[2] > $tempmax) { printf("Component above maximum temperature ($tempmax) :\n"); printf("@results[$i]"); $overtemp = "TRUE"; } } if ($overtemp eq "TRUE") { for ($i=0; $i<$j; $i++) { printf("@results[$i]"); } } exit 0; From: Michael Kalus <mkalus@rim.net> There is a script for bigbrother on ftp.deadcat.net that might help you to get a start on it. From: michael.wilkinson@twcable.com http://www.komar.org/komar/alek/pres/gettemp/ From: Josh Glover <jmglov@incogen.com> Something like the below perl script should work. You would want to stick it in your crontab like: /usr/platform/sun4u/sbin/prtdiag -v | ./scanenv.pl | mail \ you@wherever.com scanenv.pl ---------------------------------------------------------- #!/usr/bin/perl # Printing is off initially my $print = 0; # Print a subject line my $hostname = `hostname`; print "Subject: Temperature Report for $hostname\n\n"; while( <STDIN> ) { # Look for the start of the System Temperatures section if( $_ =~ /System\sTemperatures/ ){ $print = 1; } # If $print is true, print out the line if( $print ){ print $_; } # Look for the end of the System Temperatures section if( $_ =~ /\=\=\=\=\=\=\=\=\=\=/ ){ $print = 0; } } # while (eat STDIN) From: G W Cantello <glenn.w.cantello@opg.com> To run everyday at 0300h from crontab and mail to you at your_email crontab -e (to edit your crontab file) and enter the line: 00 03 * * * /usr/platform/sun4u/sbin/prtdiag | grep 'Environmental \ Status' | /usr/ucb/Mail -s "subject" your_email no script needed From: Albert White - SUN Ireland <albert.white@ireland.sun.com> Different types of machines have different formats of prtdiag output, but for a 6500 you could use something like this rather inelegant perl: --- #!/usr/bin/perl my @prtdiag=`/usr/platform/sun4u/sbin/prtdiag -v`; my $temp_flag=0; print "\nTemperature Stats\n"; for (@prtdiag){ if($temp_flag){ printf $_; if (m/^ *$/){ exit(0); } } if(m/System Temperatures/){ shift @prtdiag; shift @prtdiag; shift @prtdiag; $temp_flag=1; } } --- From: Benjamin Ritcey <sunmanagers@ritcey.com> If not exactly what you want, it should be a start; will spit out the temp of CPU0 (this is from an E250), or whichever temp probe is given as an argument (CPU1, SCSI, etc. - list at the end of the script). I call this via extended SNMP entries, each one with the appropriate arguement, to check temps and make pretty graphs. #!/bin/sh diag='/usr/platform/sun4u/sbin/prtdiag -v' probe='CPU0' if [ $# -gt 0 ]; then probe=$1 fi $diag|/bin/grep $probe| /bin/awk '{print $2}' ## values in Celcius: # CPU0 43 # CPU1 42 # MB0 34 # MB1 30 # PDB 29 # SCSI 26 From: Damir Delija <damir.delija@pbz.hr> Go to my home page http://jagor.srce.hr/ddelija there is link to the enviromental status monitoring script on Big Brother archive you can simply modify it for your purpose From: Claude Charest <charest@Canr.Hydro.Qc.Ca> Here I have installed somes scripts to monitor the temperature of my Ultra-Enterprise E3500. I send you copies of thoses scripts installed in /opt/temper: > -rwxr-xr-x 112/73 0 Jul 11 13:03 2002 temper/ > -rwxr-xr-x 112/73 1180 Jul 19 09:43 2000 temper/snap > -rw-r--r-- 0/1 2016 Aug 17 08:50 2000 temper/out.temps > -rwxr-xr-x 112/1 1095 Aug 14 11:41 2000 temper/voir > -rwxr-xr-x 0/1 121 Aug 7 15:21 2000 temper/imprime The goal is to extract by cron (with snap) this part of the "/usr/platform/`uname -i`/sbin/prtdiag -v" command in a file (/opt/temper/out.temps). The various temps are extracted each 10 minutes with my snap script and the results of each day are then printed each night using gnuplot (with imprime) ... The crons entrys are: > 0,10,20,30,40,50 * * * * /opt/temper/snap > 55 23 * * * /opt/temper/imprime I wish you all an enjoyable and problem-free weekend. Best regards, Mark Mahabir _______________________________________________ sunmanagers mailing list sunmanagers@sunmanagers.org http://www.sunmanagers.org/mailman/listinfo/sunmanagersReceived on Fri Jul 12 12:38:23 2002
This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:42:48 EST