[Nagiosplug-help] Avoiding tmp-files for SNMP-check

Andreas Baetz lac01 at web.de
Fri Nov 10 07:21:41 CET 2006


On Thursday 09 November 2006 20:33, Ingo Lantschner wrote:
> Hello,
> I wrote a plugin to check the fanstatus in FuSi Servers. The complete  
> script is attached at the end of this email.
> 
> The plugin works, but what I dont like so much ist this part:
> OUTPUT=/tmp/$1-fancheck.tmp
> snmpwalk -mAll -v1 -c $2 $1 1.3.6.1.4.1.231.2.10.2.2.5.2.2.1 > $OUTPUT
> 
> Using  tempfile is not recommended according to the guidelines for  
> nagiosplugins. But how can I store a "multiline-variable" and "grep"  
> single lines of it later on?
> 
> For the moment I do it like this:
> FANSPRESENT=$(grep fanStatus $OUTPUT | grep -v unknown | \
> 	cut -d " " -f1 | cut -d \. -f2-3)
>          for FID in $FANSPRESENT; do
>              FNAME=$(cat $OUTPUT | grep fans.16.$FID | cut -d: -f4)
> 	    ...
> 
> May be some of you already came over this prblem - thanks for any  
> hint! Ingo.

You could use perl like that:

-------------------------------------------------------------------------------
/usr/bin/perl -w
my cmd="/path/command";
my @result; # holds the output of your command
open IN, "$command |" or die "Can't run $command: $!";
while (<IN>) {
 # $_ holds the lines of output of the command
 # remove CR/LF
 chomp;
 push (@result, $_);
}

# do something with the output:
foreach (@result) { 
 # $_ holds the lines of output of the command
 if (/searchstring/i) {
  # etc, etc
 }
}
-------------------------------------------------------------------------------

Andreas


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************





More information about the Help mailing list