?
Solved

Enhanced count script wrapper

Posted on 2009-04-28
28
Medium Priority
?
225 Views
Last Modified: 2012-05-06
I have this a code that was created here, I need someones expertise  to modify it slightly and I am not sure where to start or yet fully understand the logic.


Right now the code works like this: Reference post :
http://www.experts-exchange.com/Programming/Languages/Scripting/Q_24349421.html#a24249912

 I am trying to get a script to read my m-names.txt which has lots of
167.0.0.0/8
168.0.0.0/8
192.0.0.0/8

I need to strip the / part and only use the subnet address:
167.0.0.0

Then feed it into a cli called getobjectlst.exe with a -a flag that puts the subnet address from m-names.txt

This produces a report that looks like:

"167.227.31.14"  "brs2002_204"  "Server"        "Static"        "dc.dk.sark.com"
"167.227.31.15"  "brs2005_284"  "Server"        "Static"        "dc2.dk.sark.com"
"167.227.31.16"  "brs2003"      "Server"        "Static"        "dc4.dk.sark.com"

I am intrested in the 4th field entry value and how many (count) they are per $subnet=

I get a report on how many types etc... works great,

But I need it to also do another task, when I run this script I could run into a senerio like this:
Error 48: This subnet does not exist.
146.149.0.0
getobjectlst.exe :146.149.0.0:  Error code = 48

If I get an message like that, I need the script to engage in another routine;
If that subnet has that error 48" this subnet does not exist" then and run another cli called "getsubnetlst.exe" like so

 ./getsubnetlst.exe -u Xxx -p Xxx -a 146.149.0.0 -t netwrok -o rich

This will produce relatively the  same output as in the first code:
"East"  "146.149.1.0"  "N"  ""  "146.149.0.0"  " "  " "  "255.255.255.128"
"West-Subnet"  "146.149.16.0"  "Y"  ""  "146.149.0.0"  " "  " "  "255.255.255.252"
"North Subnet"  "146.149.16.128"  "Y"  ""  "146.149.0.0"  " "  " "  "255.255.255.240"
"Asia D-NAT"  "146.149.22.0"  "Y"  ""  "146.149.0.0"  " Japan"  " "  "255.255.255.0"

Then I need to run the same cli getobjectlst.exe and reference the subnet address in the second whitespace(146.149.1.0) for each one that It reports like on the above script on line 11

$ ./getobjectlst.exe -u Xxx-p Xxx -a 146.149.16.0 -o rich
"146.149.16.1"  "srv114096srv"  "Server"        "Static"        "chase.com"
"146.149.16.2"  "srv114097srv"  "Server"        "Static"        "chase.com"

For the report, I need it to be outputed as csv so I can import it into a spreadsheet, I envision it like so

 ( never mind on the header, I will create those in excel, but wanted to show.


Subnet                              Static                 DHCP                            Unused
146.149.16.0                      363                        0                                    57

I guess the output could be like this, then I will copy/paste it.
146.149.16.0,363,0,157

Then loop and do it all until its done.

Thanks for your help in advance !



#!perl
 
open(my $log, ">log-subnet.txt") or die "Could not open log: $!\n";
 
##### Step 1, read subnets
open(my $in, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
while(<$in>) {
    next unless /(.*?)\/(.*)$/;
    my $subnet = $1;
    print "Checking $subnet\n";
    my @dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet -o rich`;
    
    my %counts;
    foreach my $line (@dnsoptions) {
        my @f = split/"\s+"/, $line;
        $counts{$f[3]}++;
    }
    
    print $log "For subnet $subnet:\n";
    foreach my $k (keys %counts) {
        print $log "    $k: $counts{$k}\n";
    }
}
 
close($log);

Open in new window

0
Comment
Question by:richsark
  • 21
  • 6
28 Comments
 
LVL 1

Author Comment

by:richsark
ID: 24254182
HI, I am just following up if I can get someone to help me please
0
 
LVL 1

Author Comment

by:richsark
ID: 24259529
Hi,

OK, I gave it a shot, see below, with my suprize, it has more errors then Microsoft :)



#!perl
 
open(my $log, ">log-subnet.txt") or die "Could not open log: $!\n";
 
##### Step 1, read subnets
open(my $in, "<m-names2.txt") or die "Could not open m-names.txt: $!\n";
while(<$in>) {
    next unless /(.*?)\/(.*)$/;
    my $subnet = $1;
    print "Checking $subnet\n";
    my @dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet -o rich`;
    
    my %counts;
    foreach my $line (@dnsoptions) {
        my @f = split/"\s+"/, $line;
        $counts{$f[3]}++;
    }
            elsif ($line =~ /^\s*Error 48: This subnet does not exist.=([^\r\n]+)/) {
            my @subnetpart2 = `./getsubnetlst.exe -u Xxx -p Xxx -a $subnet -t netwrok -o rich`;
            my @f = split/"\s+"/, $line;
            $counts{$f[3]}++;
         }
    
 printf $log "%s,%d,%d,%d\n", $subnet, ($counts{Static} or 0), ($counts{DHCP} or 0), ($counts{Unused} or 0);
 
close($log);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24266121
Hi, Could I kindly request some help?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 85

Expert Comment

by:ozo
ID: 24267600
   foreach my $line (@dnsoptions) {
            if ($line =~ /^\s*Error 48: This subnet does not exist./) {
              my @subnetpart2 = `./getsubnetlst.exe -u Xxx -p Xxx -a $subnet -t netwrok -o rich`;
          }
             my @f = split/"\s+"/, $line;
             $counts{$f[3]}++;
     }

#but I'm not sure what you want to do with @subnetpart2
0
 
LVL 1

Author Comment

by:richsark
ID: 24268582
HI Ozo,

subnetpart2 will execute getsubnetlst.exe which will produce a report like this:

East"  "146.149.1.0"  "N"  ""  "146.149.0.0"  " "  " "  "255.255.255.128"
"West-Subnet"  "146.149.16.0"  "Y"  ""  "146.149.0.0"  " "  " "  "255.255.255.252"
"North Subnet"  "146.149.16.128"  "Y"  ""  "146.149.0.0"  " "  " "  "255.255.255.240"
"Asia D-NAT"  "146.149.22.0"  "Y"  ""  "146.149.0.0"  " Japan"  " "  "255.255.255.0"

Then I need to run the same cli getobjectlst.exe and reference the subnet address in the second whitespace(146.149.1.0) for each one that It reports

$ ./getobjectlst.exe -u Xxx-p Xxx -a 146.149.16.0 -o rich
"146.149.16.1"  "srv114096srv"  "Server"        "Static"        "sark.com"
"146.149.16.2"  "srv114097srv"  "Server"        "Static"        "sark.com"

Then continue down the list until down, then start all over and go to the next subnet in the m-names.txt and so on and so forth until all done

West-Subnet"  "146.149.16.0"  "Y"  ""  "146.149.0.0"  " "  " "  "255.255.255.252"
"North Subnet"  "146.149.16.128"  "Y"  ""  "146.149.0.0"  " "  " "  "255.255.255.240"
"Asia D-NAT"  "146.149.22.0"  "Y"  ""  "146.149.0.0"  " Japan"  " "  "255.255.255.0"

Does that make sence?
0
 
LVL 1

Author Comment

by:richsark
ID: 24270270
HI, does that make sence? and will you above correction do it?

Let me know
0
 
LVL 1

Author Comment

by:richsark
ID: 24278452
Hi,

Any experts want to assist me on figuring out the missing link ?
0
 
LVL 1

Author Comment

by:richsark
ID: 24282545
HI, have a pieced this new code together from other folks who assisted me at:

http://www.unix.com/shell-programming-scripting/108484-count-script-wrapper-help-2.html

Anyway, I still cant get passed the if statement if Error 48 exists!

Any experts want to help me?


#!perl -w
my %counts;
my @subnettype;
my @dnsoptions;
my @dnsoptions2;
my @subnetpart2;
my $snetpart2;
my $subnet;
open(my $log, ">log-external-.txt") or die "Could not open log: $!\n";
printf $log "Subnet,Static,DHCP,Unused\n";
##### Step 1, read subnets
open(my $in, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
while(<$in>) {
#next unless /(.*?)\/(.*)$/;
#next unless /(.*?)$/;
chomp;
$subnet = $_;
print "Checking $subnet\n";
@dnsoptions = `./getobjectlst.exe -u xx -p xx -a $subnet -o Rich`;
# Now, at this point, we may have "Error 48" in @dnsoptions, or we may have
# the nicely formatted output. We'll have to check for both cases here.
# Let's check the unsuccessful case first. The condition below checks if
# the first element of @dnsoptions array has the following text in it -
# "Error 48: This subnet does not exist." in it.
 
if (not defined($dnsoptions[0])) {
print "dnsoptions is null or undefined, going on to the next subnet\n";
next;
 
if (join(" ",@dnsoptions) =~ /Error 48: This subnet does not exist./) {
 
# call "getsubnetlst.exe", passing $subnet as one of the parameters
@subnetpart2 = `./getsubnetlst.exe -u xx-p xx -a $subnet -t network -o Rich`;
# now loop through each element of the array @subnetpart2, which looks like this -
# ##########################################################################
# "East" "146.149.1.0" "N" "" "146.149.0.0" " " " " "255.255.255.128"
# ##########################################################################
# pick up the 2nd field from the left (e.g. 146.149.1.0 above), and pass it as
# a parameter to the cli "getobjectlst.exe".
 
 
foreach my $line (@subnetpart2) {
# get the 2nd field from the left
$snetpart2 = (split/"\s+"/, $line)[1];
# and now pass it to "getobjectlst.exe"; assign the output to
# the array @dnsoptions2
@dnsoptions2 = `./getobjectlst.exe -u xx -p xx -a $snetpart2 -o Rich`;
# find out counts of each subnettype (4th field from left)
foreach my $line (@dnsoptions2) {
@subnettype = split/"\s+"/, $line;
$counts{$subnettype[3]}++;
}
}
} else # successful output from getobjectlst.exe
{
# find out counts of each subnettype (4th field from left)
foreach my $line (@dnsoptions) {
@subnettype = split/"\s+"/, $line;
$counts{$subnettype[3]}++;
}
}
printf $log "%s,%d,%d,%d\n", $subnet, ($counts{Static} or 0), ($counts{DHCP} or 0), ($counts{Unused} or 0);
%counts = ();
}
}
close($in);
close($log);

Open in new window

0
 
LVL 39

Expert Comment

by:Adam314
ID: 24282947

open(my $log, ">log-subnet.txt") or die "Could not open log: $!\n";
 
##### Step 1, read subnets
open(my $in, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
while(<$in>) {
	next unless /(.*?)\/(.*)$/;
	my $subnet = $1;
	print "Checking $subnet\n";
	my @dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet -o rich`;
    my %counts;
	if(join("",@dnsoptions) =~ /Error 48: This subnet does not exist/i) {
		my @newlines = `./getsubnetlst.exe -u Xxx -p Xxx -a $subnet -t netwrok -o rich`;
		foreach my $line2 (@newlines) {
			my $subnet2 = (split(/"\s+"/, $line2))[1];
			@dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet2 -o rich`;
			foreach my $line (@dnsoptions)) {
				my @f = split/"\s+"/, $line;
				$counts{$f[3]}++;
			}
	    	print $log "For subnet $subnet:\n";
			foreach my $k (keys %counts) {
				print $log "    $k: $counts{$k}\n";
			}
		}
	}
	else {
		foreach my $line (@dnsoptions)) {
			my @f = split/"\s+"/, $line;
			$counts{$f[3]}++;
		}
    	print $log "For subnet $subnet:\n";
		foreach my $k (keys %counts) {
			print $log "    $k: $counts{$k}\n";
		}
	}
}
 
close($log);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24283945
Thanks Adam, will try and get back to you.

One day I want to be as smart as you :)


0
 
LVL 1

Author Comment

by:richsark
ID: 24284321

Hi Adam, I could not resists to try it, but I got some errors:

$ perl adam.pl
Bareword found where operator expected at adam.pl line 2, near ")ordie"
        (Missing operator before ordie?)
Unquoted string "ordie" may clash with future reserved word at adam.pl line 2.
String found where operator expected at adam.pl line 2, near "ordie"Could not open log: $!\n""
Unquoted string "nextunless" may clash with future reserved word at adam.pl line 7.
Backslash found where operator expected at adam.pl line 7, near ")\"
        (Missing operator before \?)
"my" variable $subnet2 masks earlier declaration in same scope at adam.pl line 16.
"my" variable @dnsoptions masks earlier declaration in same scope at adam.pl line 17.
"my" variable $line masks earlier declaration in same statement at adam.pl line 18.
"my" variable @f masks earlier declaration in same scope at adam.pl line 19.
"my" variable $subnet masks earlier declaration in same scope at adam.pl line 21.
"my" variable %counts masks earlier declaration in same scope at adam.pl line 22.
"my" variable @f masks earlier declaration in same scope at adam.pl line 30.
syntax error at adam.pl line 2, near ")ordie"
syntax error at adam.pl line 7, near "(."
syntax error at adam.pl line 14, near "){"
syntax error at adam.pl line 17, near "))"
syntax error at adam.pl line 22, near "){"
syntax error at adam.pl line 25, near "}"
syntax error at adam.pl line 31, near "}"
syntax error at adam.pl line 33, near "){"
Execution of adam.pl aborted due to compilation errors.
0
 
LVL 1

Author Comment

by:richsark
ID: 24294947
Hi, Any thoughts?
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24296164
Sounds like you are missing the space between "or" and "die" on the open statement.
0
 
LVL 1

Author Comment

by:richsark
ID: 24296195
HI,

Yup, I thought of that already, I had already changed that after I posted, here is the message  without the ordie

$ perl adam.pl
Unquoted string "nextunless" may clash with future reserved word at adam.pl line 13.
Backslash found where operator expected at adam.pl line 13, near ")\"
        (Missing operator before \?)
"my" variable $subnet2 masks earlier declaration in same scope at adam.pl line 22.
"my" variable @dnsoptions masks earlier declaration in same scope at adam.pl line 23.
"my" variable $line masks earlier declaration in same statement at adam.pl line 24.
"my" variable @f masks earlier declaration in same scope at adam.pl line 25.
"my" variable $subnet masks earlier declaration in same scope at adam.pl line 27.
"my" variable %counts masks earlier declaration in same scope at adam.pl line 28.
"my" variable %counts masks earlier declaration in same scope at adam.pl line 36.
"my" variable @f masks earlier declaration in same scope at adam.pl line 36.
syntax error at adam.pl line 13, near "(."
syntax error at adam.pl line 20, near "){"
syntax error at adam.pl line 23, near "))"
syntax error at adam.pl line 28, near "){"
syntax error at adam.pl line 31, near "}"
syntax error at adam.pl line 37, near "}"
syntax error at adam.pl line 39, near "){"
Execution of adam.pl aborted due to compilation errors.


0
 
LVL 39

Expert Comment

by:Adam314
ID: 24296921
Looks like a similar error between "next" and "unless" on line 13.
0
 
LVL 1

Author Comment

by:richsark
ID: 24297053
Hi,
what do you mean?
0
 
LVL 1

Author Comment

by:richsark
ID: 24297401
OK, I figured it out ;)

but now I got:

$ perl adam.pl
syntax error at adam.pl line 16, near "){"
syntax error at adam.pl line 19, near "))"
syntax error at adam.pl line 24, near "){"
syntax error at adam.pl line 27, near "}"
syntax error at adam.pl line 33, near "}"
syntax error at adam.pl line 35, near "){"
Execution of adam.pl aborted due to compilation errors.
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24297802
Copy and paste it exactly as it is here.
#!/usr/bin/perl
open(my $log, ">log-subnet.txt") or die "Could not open log: $!\n";
 
##### Step 1, read subnets
open(my $in, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
while(<$in>) {
	next unless /(.*?)\/(.*)$/;
	my $subnet = $1;
	print "Checking $subnet\n";
	my @dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet -o rich`;
	my %counts;
	if(join("",@dnsoptions) =~ /Error 48: This subnet does not exist/i) {
		my @newlines = `./getsubnetlst.exe -u Xxx -p Xxx -a $subnet -t netwrok -o rich`;
		foreach my $line2 (@newlines) {
			my $subnet2 = (split(/"\s+"/, $line2))[1];
			@dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet2 -o rich`;
			foreach my $line (@dnsoptions) {
				my @f = split/"\s+"/, $line;
				$counts{$f[3]}++;
			}
			print $log "For subnet $subnet:\n";
			foreach my $k (keys %counts) {
				print $log "    $k: $counts{$k}\n";
			}
		}
	}
	else {
		foreach my $line (@dnsoptions) {
			my @f = split/"\s+"/, $line;
			$counts{$f[3]}++;
		}
		print $log "For subnet $subnet:\n";
		foreach my $k (keys %counts) {
			print $log "    $k: $counts{$k}\n";
		}
	}
}
 
close($log);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24297901
I did as you said, still does not run the Error 48's

Also, is there a way we can suppress the error 48's with

running getobjectlst for Error48

$ perl adam4.pl

Checking 10.0.0.0
Checking 146.149.0.0
Error 48: This subnet does not exist.
146.149.0.0
qgetobjectlst.exe :146.149.0.0:  Error code = 48
Checking 161.16.0.0
Error 48: This subnet does not exist.
161.16.0.0

from the log.txt

For subnet 10.0.0.0:
    Static: 37
    Unused: 217
For subnet 146.149.0.0:
For subnet 161.16.0.0:
For subnet 161.56.0.0:
For subnet 162.2.0.0:
For subnet 162.5.0.0:

Also, once we get this worked out, I still would like the output to be like

146.149.16.0,363,0,157
0
 
LVL 1

Author Comment

by:richsark
ID: 24297978

HI,

I found a type on
my @newlines = `./getsubnetlst.exe -u Xxx -p Xxx -a $subnet -t netwrok -o rich`;

Changed to:

my @newlines = `./getsubnetlst.exe -u Xxx -p Xxx -a $subnet -t network -o rich`;

Still no difference

#!/usr/bin/perl
open(my $log, ">log-subnet.txt") or die "Could not open log: $!\n";
 
##### Step 1, read subnets
open(my $in, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
while(<$in>) {
        next unless /(.*?)\/(.*)$/;
        my $subnet = $1;
        print "Checking $subnet\n";
        my @dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet -o rich`;
        my %counts;
        if(join("",@dnsoptions) =~ /Error 48: This subnet does not exist/i) {
                my @newlines = `./getsubnetlst.exe -u Xxx -p Xxx -a $subnet -t network -o rich`;
                foreach my $line2 (@newlines) {
                        my $subnet2 = (split(/"\s+"/, $line2))[1];
                        @dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet2 -o rich`;
                        foreach my $line (@dnsoptions) {
                                my @f = split/"\s+"/, $line;
                                $counts{$f[3]}++;
                        }
                        print $log "For subnet $subnet:\n";
                        foreach my $k (keys %counts) {
                                print $log "    $k: $counts{$k}\n";
                        }
                }
        }
        else {
                foreach my $line (@dnsoptions) {
                        my @f = split/"\s+"/, $line;
                        $counts{$f[3]}++;
                }
                print $log "For subnet $subnet:\n";
                foreach my $k (keys %counts) {
                        print $log "    $k: $counts{$k}\n";
                }
        }
}
 
close($log);

Open in new window

0
 
LVL 39

Expert Comment

by:Adam314
ID: 24298386
if the getobjectlst program writes to stderr instead of stdout, you can fix it with:
    my @dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet -o rich 2>&1`;
0
 
LVL 1

Author Comment

by:richsark
ID: 24299057
OK, on line 16, should it be (looking at $subnet)

from:
@dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet -o rich`;
                       
To this:
my @dnsoptions = `./getobjectlst.exe -u Xxx-p Xxx -a $subnet2 -o rich 2>&1`;

Thanks
0
 
LVL 1

Author Comment

by:richsark
ID: 24299962
HI Adam, not sure... Its still doing the same thing bro.
$ perl adam4.pl
Checking 10.0.0.0
Checking 146.149.0.0
Error 48: This subnet does not exist.
146.149.0.0
getobjectlst.exe :146.149.0.0:  Error code = 48
I used:
my @dnsoptions = `./getobjectlst.exe -u xx -p xx -a $subnet2 -o rich 2>&1`;
and this way:
my @dnsoptions = `./getobjectlst.exe -u xx -p xx -a $subnet -o rich 2>&1`;  
output from the log.txt
For subnet 10.0.0.0:
    Static: 37
    Unused: 217
For subnet 146.149.0.0:
For subnet 161.16.0.0:

This is a tough one !
0
 
LVL 1

Author Comment

by:richsark
ID: 24300401
I also used:
my @dnsoptions = `./getobjectlst.exe -u xx -p xx -a $subnet -o rich >&1`;  
 
0
 
LVL 1

Author Comment

by:richsark
ID: 24301078
HI Adam,
I ventured off and got some help from another site. I appericate your help on this !
This is the code that is working.  However I am getting an EOF error.
I opened another thread on this. I hope its the right thing to do?
Thanks
Below code taken from: ( Thanks to FishMonger)
http://perlguru.com/gforum.cgi?do=post_view_flat;post=37667;page=1;mh=-1;;sb=post_latest_reply;so=ASC 

#!perl
use strict; 
use warnings; 
use Data::Dumper; 
 
open my $log, '>', 'log-external.txt' or die "Could not open log: $!"; 
print $log "Subnet,Static,DHCP,Unused\n"; 
 
open my $dump, '>', 'dump.log' or die "failed to open 'dump.log' $!"; 
 
##### Step 1, read subnets 
open my $in, '<', 'm-names.txt' or die "Could not open m-names.txt: $!\n"; 
while( my $subnet = <$in>) { 
 
    print "Checking $subnet"; 
    chomp $subnet; 
     
    my %counts = (  
                   Static => 0, 
                   DHCP   => 0, 
                   Unused => 0, 
    ); 
     
    my @dnsoptions = `./getobjectlst.exe -u xx -p xx -o rich -a $subnet 2>&1`;
 
    print $dump "dumping \@dnsoptions\n";     
    print $dump Data::Dumper->Dump(\@dnsoptions); 
    print $dump '=' x 25, "\n"; 
 
    if ( @dnsoptions and $dnsoptions[0] eq '' ) {
        print "dnsoptions is null or undefined, going on to the next subnet\n"; 
        next; 
    } 
 
    # Now, at this point, we may have "Error 48" in @dnsoptions, or we may have 
    # the nicely formatted output. We'll have to check for both cases here. 
    # Let's check the unsuccessful case first. The condition below checks if 
    # the first element of @dnsoptions array has the following text in it - 
    # "Error 48: This subnet does not exist." in it. 
 
 
    if (join("",@dnsoptions) =~ /Error 48: This subnet does not exist./) { 
 
        # call "getsubnetlst.exe", passing $subnet as one of the parameters 
        my @subnetpart2 = `./getsubnetlst.exe -u xx-p xx -o rich -a $subnet -t network`; 
 
        print $dump "dumping \@subnetpart2\n";     
        print $dump Data::Dumper->Dump(\@subnetpart2); 
        print $dump '=' x 25, "\n"; 
 
         
        # now loop through each element of the array @subnetpart2, which looks like this - 
        # ########################################################################## 
        # "East" "146.149.1.0" "N" "" "146.149.0.0" " " " " "255.255.255.128" 
        # ########################################################################## 
        # pick up the 2nd field from the left (e.g. 146.149.1.0 above), and pass it as 
        # a parameter to the cli "getobjectlst.exe". 
 
 
        foreach my $line ( @subnetpart2 ) { 
 
            # get the 2nd field from the left 
            my $snetpart2 = (split/"\s+"/, $line)[1];
 
            # and now pass it to "getobjectlst.exe"; 
            my @dnsoptions2 = `./getobjectlst.exe -u xx -p xx -o rich -a $snetpart2`;
 
            print $dump "dumping \@dnsoptions2\n";     
            print $dump Data::Dumper->Dump(\@dnsoptions2); 
            print $dump '=' x 25, "\n"; 
             
            # find out counts of each subnettype (4th field from left) 
            foreach my $line (@dnsoptions2) { 
                my @subnettype = split/"\s+"/, $line; 
                $counts{$subnettype[3]}++; 
            } 
        } 
    } 
    else { # successful output from getobjectlst.exe 
 
        # find out counts of each subnettype (4th field from left) 
        foreach my $line (@dnsoptions) { 
            my @subnettype = split/"\s+"/, $line;
            $counts{$subnettype[3]}++; 
        } 
    } 
    printf $log "%s,%d,%d,%d\n", $subnet, $counts{Static}, $counts{DHCP}, $counts{Unused}; 
} 
 
close($in); 
close($log);

Open in new window

0
 
LVL 39

Accepted Solution

by:
Adam314 earned 2000 total points
ID: 24307216
If this question has been answered, then it should be closed, or deleted.  I'll probably see your new thread (if it's at EE), and will try to help there.
0
 
LVL 1

Author Comment

by:richsark
ID: 24307452
Hi Adam, ok will do, The thread is located at:

http://www.experts-exchange.com/Programming/Languages/Scripting/Q_24380006.html

Thanks see you there !


0
 
LVL 1

Author Closing Comment

by:richsark
ID: 31575425
Thanks once more
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question