in reply to Need help with SNMP script

To make the existing code work you need to skip the lines that don't have enough elements for the split to return for your comparisons:

while (<SNMP>) { next if /^#|^\s*$/; ...

or try this to use a regular expression instead;

while (<DATA>) { print "$1\n" if /^snmpmanager\s+(\d+\.\d+\.\d+\.\d+)\s+;\s+communi +tyname/; } __DATA__ #test file #example: snmpmanager 10.52.37.99 ; communityname public

Replies are listed 'Best First'.
Re^2: Need help with SNMP script
by Xandrex (Initiate) on Oct 04, 2011 at 18:55 UTC

    Hi Lotus1, thanks for the quick response. We have another systems using the same script and it is running fine, so I would rather not make changes. I read elsewhere on this site that the warning "Use of uninitialized value in string eq" is just that, a warning. I guess I am just confused and don't understand what the expression is trying to do because I really don't understand the code. I don't know anything about code. I had to google
    just to write the original post.

      Sounds to me like the trap.cfg file must be different on the other machine. You could get ride of the comment lines (lines that start with '#'). Compare the cfg files for differences.

      <SNMP> is reading a line from the file in $naspath. The line gets split into the @token array and the elements compared with strings.