ONTAP Discussions

Perl assistance parsing sysconfig-m

willd
3,073 Views

I need to pull some DIMM information out of a sysconfig-m file.

I have a script that can pull the data and gives me what I need, but it is looping around 4 times before exiting.

Can someone give me an idea of what is going on? I am very PERL challenged.

### check args

#

if ($#ARGV == 1) {             ### there should be four arguments

          $cust   = $ARGV[0];

          $file   = $ARGV[1];

} else {                       ### else wrong number of arguments

          print "\nUsage: disk_rpt.pl <customer> <file>\n\n";

          print "<file> is the name of a text file containing serial numbers\n\n";

          exit 1;

} #end if

$count=0;

$count_host=0;

########################################################################

### Global variables

###

$root                = "\\ntstp";

########################################################################

########################################################################

### cycle through files listed in file denoted by command-line argument

###

open (SYSTEMS, "$file") or die "cannot open systems file\n";

FILER: while ( <SYSTEMS> ) {

   $serial = $_; chop $serial;

          system ("${root}\\ntstp_asup_fetch.pl -s SYSCONFIG-M -w ${serial} > ${root}\\temp.txt" );

          open (SYSCONFIG, "${root}\\temp.txt") or die "cannot open temp.txt\n";

               while ( <SYSCONFIG> ) {

                              if (m/hostname/) {

                                        ($leading,$host_tag,$hostname,$serialno,$serialnumber) = split;

                         } #end if

 

                            if (m/DIMM/) {

                                   $leading = 0;

                                   $dimm = 0;

                                   $part = 0;

                                   $dimm_serial = 0;

                                   $count ++; #checking how many times it is running through

                    ($leading,$dimm,$part,$dimm_serial) = split('!');

                                        print "#$count  | ${serial} | ${dimm} | ${part} |${dimm_serial}\n";

                    }

          } #end while SYSCONFIG

 

          close ( SYSCONFIG );

          system ("del ${root}\\temp.txt");

} #end while FILER

Output I am getting:

C:\ntstp>dimm_rpt.pl avnet test.txt

#1  | 600000248761 | DIMM-1 | 40-01-1241-01176538 |VR7VA127258GBZN3

#2  | 600000248761 | DIMM-NV1 | 40-01-1244-01181020 |VR7VA567258GBZN3

#3  | 600000248761 | DIMM-1 | 40-01-1241-01176538 |VR7VA127258GBZN3

#4  | 600000248761 | DIMM-NV1 | 40-01-1244-01181020 |VR7VA567258GBZN3

#5  | 600000248761 | DIMM-1 | 40-01-1241-01176538 |VR7VA127258GBZN3

#6  | 600000248761 | DIMM-NV1 | 40-01-1244-01181020 |VR7VA567258GBZN3

#7  | 600000248761 | DIMM-1 | 40-01-1241-01176538 |VR7VA127258GBZN3

#8  | 600000248761 | DIMM-NV1 | 40-01-1244-01181020 |VR7VA567258GBZN3

2 REPLIES 2

eric8
3,073 Views

Can you provide the test.txt and the temp.txt contents?

lewisn
3,073 Views

I had to make a couple mods to run on my mac in regards to file name convention. You also needed the -L option in the ASUP fetch script call.

My input file is structured 1 serial per line, if you need it in a space or comma delimited list it is easy enough to parse but require additional code.

Try this out:

#!/usr/bin/perl

use warnings;

use strict;

########################################################################

### Global variables

###

my ($args,$cust,$file,$count,$count_host,$root,$tmpFile );

########################################################################

### check args

#

if ( $#ARGV == 1 ) {             ### there should be four arguments

          $cust   = $ARGV[0];

          $file   = $ARGV[1];

} else {                       ### else wrong number of arguments

          print "\nUsage: disk_rpt.pl <customer> <file>\n\n";

          print "<file> is the name of a text file containing serial numbers\n\n";

          exit 1;

} #end if

$count=0;

$count_host=0;

#$root                = "\\ntstp";

$root                = "";

#$tmpFile               = "$root\\temp.txt";

$tmpFile      = "temp.txt";

########################################################################

### cycle through files listed in file denoted by command-line argument

###

open (SYSTEMS, "$file") or die "cannot open systems file\n";

FILER: while ( <SYSTEMS> ) {

   my ($serial,$leading,$host_tag,$hostname,$serialno,$serialnumber,$dimm,$part,$dimm_serial);

   $serial = $_; chop $serial;

          system ("perl ./ntstp_asup_fetch.pl -s SYSCONFIG-M -L -w ${serial} > $tmpFile" );

          open (SYSCONFIG, "$tmpFile") or die "cannot open $tmpFile\n";

               while ( <SYSCONFIG> ) {

                              if (m/hostname/) {

                                        ($leading,$host_tag,$hostname,$serialno,$serialnumber) = split;

                         } #end if

                            if (m/DIMM/) {

                                   $leading = 0;

                                   $dimm = 0;

                                   $part = 0;

                                   $dimm_serial = 0;

                                   $count ++; #checking how many times it is running through

                    ($leading,$dimm,$part,$dimm_serial) = split('!');

                                        print "#$count  | ${serial} | ${dimm} | ${part} |${dimm_serial}\n";

                    }

          } #end while SYSCONFIG

          close ( SYSCONFIG );

          if (-f $tmpFile) {

                    unlink $tmpFile;

          }

          #system ("del ${root}\\temp.txt");

} #end while FILER

Public