Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spliting up data

Status
Not open for further replies.

sumncguy

IS-IT--Management
Joined
May 22, 2006
Messages
118
Location
US
I am trying to make the transition from shell to perl.

My cheap code

#!/usr/local/bin/perl -w
#
use lib '/perl/arch';
use lib '/perl/lib';
#
open(IPL, "$ARGV[0]");
$commstrng = "$ARGV[1]";
#
while($bulls = <IPL>) {
chomp($bulls);
@Sysob=`/usr/local/bin/snmpwalk -c $commstrng $bulls system 2>/dev/null`;
@xray = split(/,/,$Sysob[1]);
print "$xray[1]\n";
}



The output

SNMPv2-MIB::sysDescr.0 = STRING: Cisco Internetwork Operating System Software
IOS (tm) C3550 Software (C3550-I5K2L2Q3-M), Version 12.1(13)EA1c, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2003 by cisco Systems, Inc.
Compiled Tue 24-Jun-03 19:30 by yenanh
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.9.1.367
SNMPv2-MIB::sysUpTime.0 = Timeticks: (1781498469) 206 days, 4:36:24.69
SNMPv2-MIB::sysContact.0 = STRING:xxxx
SNMPv2-MIB::sysName.0 = STRING: xxxxxxx
SNMPv2-MIB::sysLocation.0 = STRING: 6xxxxxx, CA 92660
SNMPv2-MIB::sysServices.0 = INTEGER: 6
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00

How many lines in this walk ?
> snmpwalk -c xxxxxx! xxxxx system | wc -l
11

The problem is that response to the ISO system variable will not always be in the same format or the same length(in lines). Im not sure how to deal with that.

I know I can use split, index and rindex to extract the data I need .. but the output may be junk depending upon the initial result.


@xray = split(/,/,$Sysob[1]);
print "$xray[1]\n"; .... may not always be
" Version 12.1(13)EA1c"

Thanks for helping this perl rookie.


 
is the output always comma seperated? Maybe something like this would work:

Code:
#!/usr/local/bin/perl -w
#
use lib '/perl/arch';
use lib '/perl/lib';
#
open(IPL, "$ARGV[0]");
$commstrng = "$ARGV[1]";
#
$not_found = 1;
while($bulls = <IPL>) {
   chomp($bulls);
   @Sysob=`/usr/local/bin/snmpwalk -c $commstrng $bulls system 2>/dev/null`;
   for(@Sysob) {
      if (/version/i) {
         $not_found = 0; 
         print "$_\n";
         last;
      }
   }
}
if ($not_found) {
   print "No Version was found\n";
}

- Kevin, perl coder unexceptional!
 

Humm that should work ... but I thing it might get a little hairy as I parse through for bits and pieces of the snmpwalk response .. system name, version, model etc etc. But you have given me a direction to follow.

Thanks
 
If you can never be sure of the format or placement of the data you are searching for you have to go fishing with some bait. The bait can be regexp's or index() or other string/pattern searching method, but you will have to go fishing.

The trick is to get your data as normalized as possible before processing the data. But sometimes that just can't be done and the only method left is brute-force searches using a series of regexp's.

- Kevin, perl coder unexceptional!
 

Thanks again Kevin. I think the brute force method in some capacity will be needed. ... lotsa ugly if this then that type stuff ... srting =~ m/xx/ stuff ... Oh well gotta do whatch gotta do.

Thanks for the help man and Happy Thanksgiving !!!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top