Solved

Help with EOF error in script

Posted on 2009-05-04
49
468 Views
Last Modified: 2012-05-06
Hello, In this script, I am getting these errors

sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file

Can someone look at this and advice

Thanks
#!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
Comment
Question by:richsark
  • 27
  • 22
49 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 24301093
what is in $subnet when you do
`./getsubnetlst.exe -u xx-p xx -o rich -a $subnet -t network`
what is in  $snetpart2 when you do
`./getobjectlst.exe -u xx -p xx -o rich -a $snetpart2`
0
 
LVL 1

Author Comment

by:richsark
ID: 24301113
Hi Ozo,
I have a bunch of lines like this:
 
$ ./getsubnetlst.exe -u xx -p xx -o rich  -a 146.149.0.0/16 -t network

"Nat-Bogota-China"  "146.149.1.0"  "N"  ""  "146.149.0.0"  " "  " "  "255.255.255.128"
" imported subnet"  "146.149.16.0"  "Y"  ""  "146.149.0.0"  " "  " "  "255.255.255.252"
"imported1 subnet"  "146.149.16.128"  "Y"  ""  "146.149.0.0"  " "  " "  "255.255.255.240"
When I run this, I have bunch of lines like these:
$ ./getobjectlst.exe -u xx  -p xx  -o rich -a 146.149.1.0
"146.149.1.1"   ""      ""      "Unused"        ""
"146.149.1.2"   ""      ""      "Unused"        ""
"146.149.1.3"   ""      ""      "Unused"        ""
"146.149.1.4"   ""      ""      "Unused"        ""
"146.149.1.5"   ""      ""      "Unused"        ""
"146.149.1.6"   ""      ""      "Unused"        ""
"146.149.1.7"   ""      ""      "Unused"        ""
Does that help?
0
 
LVL 84

Expert Comment

by:ozo
ID: 24301243
which of those lines gets the error?
0
 
LVL 1

Author Comment

by:richsark
ID: 24303735
HI Ozo, I would think it starts at line 52 when its doing stuff with teh Error 48
The error message that I got does not tell me which line.
Thanks
0
 
LVL 1

Author Comment

by:richsark
ID: 24304896
I put it under debug,
see if this provides any clues:
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
main::(fish3.pl:68):                print $dump "dumping \@dnsoptions2\n";
  DB<1> n
main::(fish3.pl:69):                print $dump Data::Dumper->Dump(\@dnsoptions2);
  DB<1> n
main::(fish3.pl:70):                print $dump '=' x 25, "\n";
  DB<1> n
main::(fish3.pl:73):                foreach my $line (@dnsoptions2) {
  DB<1> n
main::(fish3.pl:63):                my $snetpart2 = (split/"\s+"/, $line)[1];
  DB<1> n
main::(fish3.pl:66):                my @dnsoptions2 = `./getobjectlst.exe -u x -p x-o rich -a $snetpart2`;
  DB<1> n
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
main::(fish3.pl:68):                print $dump "dumping \@dnsoptions2\n";
0
 
LVL 84

Expert Comment

by:ozo
ID: 24306456
may we see what was printed to $dump, and what was in $snetpart2>
0
 
LVL 1

Author Comment

by:richsark
ID: 24306590
The dump.log shows
 
dumping @dnsoptions
$VAR1 = '"10.0.0.1"      ""      ""      "Unused"      ""
';
$VAR2 = '"10.0.0.2"      ""      ""      "Unused"      ""
';
$VAR3 = '"10.0.0.3"      "sarkie-04crp-w04"      "Switch"      "Static"      "netdevice.sark.com"
';
$VAR4 = '"10.0.0.4"      ""      ""      "Unused"      ""
';
$VAR5 = '"10.0.0.5"      ""      ""      "Unused"      ""
';
$VAR6 = '"10.0.0.6"      "rich-ntp-server"      "Server"      "Static"      "netdevice2.sark.com"
';
$VAR254 = '"10.0.0.254"      ""      ""      "Unused"      ""
=========================
dumping @dnsoptions
=========================
dumping @dnsoptions
=========================
dumping @dnsoptions
=========================
dumping @dnsoptions
=========================
dumping @dnsoptions

 
 
0
 
LVL 1

Author Comment

by:richsark
ID: 24306655
for the next part: subnetpart2 which is in the same dump.log
=========================
dumping @dnsoptions
$VAR1 = '146.149.0.0/16
';
$VAR2 = 'getobjectlst.exe :146.149.0.0/16:  Error code = 48
';
$VAR3 = 'Error 48: This subnet does not exist.
';
=========================
dumping @subnetpart2
$VAR1 = '"Nat-Colombia"  "146.149.1.0"  "N"  ""  "146.149.0.0"  " "  " "  "255.255.255.128"
';
$VAR2 = '"Apogee"  "146.149.16.0"  "Y"  ""  "146.149.0.0"  " "  " "  "255.255.255.252"
 
0
 
LVL 84

Expert Comment

by:ozo
ID: 24306667
may we see what was in $snetpart2 ?
0
 
LVL 1

Author Comment

by:richsark
ID: 24306697
Hi, I have shown it above, I guess we crossed posts.

Is that what you are looking for?
0
 
LVL 84

Expert Comment

by:ozo
ID: 24306730
I don't see where you are dumping \@dnsoptions2\n

If you send both STDERR and $snetpart2 and perhaps $line to $dump we may be able to see which $line is causing the error
0
 
LVL 84

Expert Comment

by:ozo
ID: 24306749
where did you show $snetpart2 ?
0
 
LVL 1

Author Comment

by:richsark
ID: 24306803
Ok, I put the script in debug and I see that option @dnsoptions2\n";

main::(fish3.pl:63):                my $snetpart2 = (split/"\s+"/, $line)[1];
  DB<1>
main::(fish3.pl:66):                my @dnsoptions2 = `./getobjectlst.exe -u xx  -p xx -o rich -a $snetpart2`;
  DB<1>
main::(fish3.pl:68):                print $dump "dumping \@dnsoptions2\n";
  DB<1>
main::(fish3.pl:69):                print $dump Data::Dumper->Dump(\@dnsoptions2);
  DB<1>
main::(fish3.pl:70):                print $dump '=' x 25, "\n";
  DB<1>
main::(fish3.pl:73):                foreach my $line (@dnsoptions2) {
  DB<1>
main::(fish3.pl:74):                    my @subnettype = split/"\s+"/, $line;
  DB<1>
main::(fish3.pl:75):                    $counts{$subnettype[3]}++;
  DB<1>
main::(fish3.pl:74):                    my @subnettype = split/"\s+"/, $line;
  DB<1>
main::(fish3.pl:75):                    $counts{$subnettype[3]}++;
  DB<1>
main::(fish3.pl:74):                    my @subnettype = split/"\s+"/, $line;
  DB<1>
main::(fish3.pl:75):                    $counts{$subnettype[3]}++;
Is this what you are reffering to? if not please advice
0
 
LVL 84

Expert Comment

by:ozo
ID: 24306879
I saw where you
main::(fish3.pl:68):                print $dump "dumping \@dnsoptions2\n";
 DB<1> n
main::(fish3.pl:69):                print $dump Data::Dumper->Dump(\@dnsoptions2);
nit I only saw
dumping @dnsoptions
not
dumping @dnsoptions2
in the dump log

and we still have no dump of $snetpart2


if you can show $snetpart2 and $line together with STDERR,
we may be able to find the $line that causes the error
0
 
LVL 1

Author Comment

by:richsark
ID: 24306912
Hi,
How is this:
main::(fish3.pl:63):                my $snetpart2 = (split/"\s+"/, $line)[1];
  DB<1>
main::(fish3.pl:66):                my @dnsoptions2 = `./getobjectlst.exe -u xx -p xx -o rich -a $snetpart2`;
  DB<1>
main::(fish3.pl:68):                print $dump "dumping \@dnsoptions2\n";
  DB<1>
main::(fish3.pl:69):                print $dump Data::Dumper->Dump(\@dnsoptions2);
  DB<1>
main::(fish3.pl:70):                print $dump '=' x 25, "\n";
  DB<1>
main::(fish3.pl:73):                foreach my $line (@dnsoptions2) {
  DB<1>
main::(fish3.pl:74):                    my @subnettype = split/"\s+"/, $line;
  DB<1>
main::(fish3.pl:75):                    $counts{$subnettype[3]}++;
  DB<1>
main::(fish3.pl:74):                    my @subnettype = split/"\s+"/, $line;
  DB<1>
main::(fish3.pl:75):                    $counts{$subnettype[3]}++;
  DB<1>
main::(fish3.pl:63):                my $snetpart2 = (split/"\s+"/, $line)[1];
  DB<1>
main::(fish3.pl:66):                my @dnsoptions2 = `./getobjectlst.exe -u xx  -p xx  -o rich -a $snetpart2`;
0
 
LVL 1

Author Comment

by:richsark
ID: 24306950
Another attempt
63:                 my $snetpart2 = (split/"\s+"/, $line)[1];
64
65                  # and now pass it to "getobjectlst.exe";
66==>               my @dnsoptions2 = `./getobjectlst.exe -u xx  -p xx  -o rich -a $snetpart2`;
67
68:                 print $dump "dumping \@dnsoptions2\n";
69:                 print $dump Data::Dumper->Dump(\@dnsoptions2);
70:                 print $dump '=' x 25, "\n";
71
72                  # find out counts of each subnettype (4th field from left)
0
 
LVL 84

Expert Comment

by:ozo
ID: 24306979
can you show $snetpart2 together with the error message?
0
 
LVL 1

Author Comment

by:richsark
ID: 24307382
hi ozo, I ran the script with perl -d script_name.pl
I dont see that EOF error message. What am I doing wrong, or what is the best way to get this produced?
0
 
LVL 84

Expert Comment

by:ozo
ID: 24307487
if you are no longer getting the error messages, does that mean it is fixed?
0
 
LVL 1

Author Comment

by:richsark
ID: 24307552
Hi,

No, I just cant seem to see it under debug, but when I run it normally, I see it on the screen

0
 
LVL 1

Author Comment

by:richsark
ID: 24307828
Ok, I got something
 
main::(fish3.pl:43):        if (join("",@dnsoptions) =~ /Error 48: This subnet does not exist./) {
  DB<1>
main::(fish3.pl:46):            my @subnetpart2 = `./getsubnetlst.exe -u xx  -p xx -o rich -a $subnet -t network`;
  DB<1>
main::(fish3.pl:48):            print $dump "dumping \@subnetpart2\n";
  DB<1>
main::(fish3.pl:49):            print $dump Data::Dumper->Dump(\@subnetpart2);
  DB<1>
main::(fish3.pl:50):            print $dump '=' x 25, "\n";
  DB<1>
main::(fish3.pl:61):            foreach my $line ( @subnetpart2 ) {
  DB<1>
main::(fish3.pl:64):                my $snetpart2 = (split/"\s+"/, $line)[1];
  DB<1>
main::(fish3.pl:67):                my @dnsoptions2 = `./getobjectlst.exe -u xx  -p xx -o rich -a $snetpart2`;
  DB<1>
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
main::(fish3.pl:69):                print $dump "dumping \@dnsoptions2\n";
  DB<1>
main::(fish3.pl:70):                print $dump Data::Dumper->Dump(\@dnsoptions2);
  DB<1>
main::(fish3.pl:71):                print $dump '=' x 25, "\n";
0
 
LVL 84

Expert Comment

by:ozo
ID: 24307870
can you print $snetpart2
where the error appears?
0
 
LVL 1

Author Comment

by:richsark
ID: 24307906
Ok,
 
$ perl fish3.pl

Checking 162.2.0.0/16  "162.2.1.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.2.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.3.0sh: -c: line 0: unexpected EOF while looking for matching `"'
0
 
LVL 1

Author Comment

by:richsark
ID: 24307942
A bit more:
3798"162.2.28.252Unused"
3799"162.2.28.253Unused"
3800"162.2.28.254Unused"
3801  "162.2.29.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.30.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.31.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.32.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.35.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.36.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.37.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.38.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.39.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.40.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.43.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.44.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.45.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.46.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.51.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.52.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.53.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.54.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
  "162.2.80.0sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
162.2.81.0"162.2.81.1"  ""      ""      "Unused"        ""
"162.2.81.2"    ""      ""      "Unused"        ""
"162.2.81.3"    ""      ""      "Unused"        ""
"162.2.81.4"    ""      ""      "Unused"        ""
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 84

Expert Comment

by:ozo
ID: 24307981
was  any of that $snetpart2 or $line?
0
 
LVL 1

Author Comment

by:richsark
ID: 24308024
Yes;
foreach my $line ( @subnetpart2 ) {
 
            # get the 2nd field from the left
            print my $snetpart2 = (split/"\s+"/, $line)[1];
 
            # and now pass it to "getobjectlst.exe";
           print 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) {
               print my @subnettype = split/"\s+"/, $line;
               print $counts{$subnettype[3]}++;  
0
 
LVL 84

Expert Comment

by:ozo
ID: 24308134
what part of the output came from the
  print my $snetpart2 = (split/"\s+"/, $line)[1];
0
 
LVL 84

Expert Comment

by:ozo
ID: 24308160
if it was the
  "162.2.30.0
that has an unmatched " that could explain the error
0
 
LVL 1

Author Comment

by:richsark
ID: 24308203
I dont understand sir
0
 
LVL 84

Expert Comment

by:ozo
ID: 24308258
if the print my $snetpart2 = (split/"\s+"/, $line)[1];
is what printed the
  "162.2.30.0
it would mean that $snetpart2 eq '"162.2.30.0'
and that you were executing
`./getobjectlst.exe -u xx  -p xx -o rich -a "162.2.30.0`
which has no match for the "
0
 
LVL 1

Author Comment

by:richsark
ID: 24308269
ok, so how can we fix it not to show the error?, or is it not an issue to have it display
0
 
LVL 1

Author Comment

by:richsark
ID: 24308329
ahh.. so we have a " somewhere that needs to come out, or recode that line right?

If so, can you be so kind to provide that please.

Thanks
0
 
LVL 84

Expert Comment

by:ozo
ID: 24308338
if the print my $snetpart2 = (split/"\s+"/, $line)[1];
is what printed the
  "162.2.30.0
then I'm wondering what  $line was
since it may indicate that it did not look the way you expected it to.
But if you wanted to execute
./getobjectlst.exe -u xx  -p xx -o rich -a 162.2.30.0
rather than
./getobjectlst.exe -u xx  -p xx -o rich -a "162.2.30.0
then you would need to remove the "
0
 
LVL 1

Author Comment

by:richsark
ID: 24308393
ok, so how can we re-write it to either ignore it or do something else with it?
0
 
LVL 84

Expert Comment

by:ozo
ID: 24308489
print my $snetpart2 = (split/"\s+"/, $line)[1];
if( $snetpart2 =~ /"/ ){
   warn "\$snetpart iwas $snetpart\nwhen \$line was $line";
   next;  
}
#or, if the only problem was an extra ", you might just  $snetpart2 =~s/"//g;
0
 
LVL 1

Author Comment

by:richsark
ID: 24308588
Ok, I added:
my $snetpart2 =~s/"//g;

Checking 162.2.0.0/16Use of uninitialized value $snetpart2 in substitution (s///) at fish3.pl line 64, <$in> line 1
Use of uninitialized value $snetpart2 in concatenation (.) or string at fish3.pl line 68, <$in> line 1.
0
 
LVL 84

Expert Comment

by:ozo
ID: 24308619
If there was no "\s+" in $line, then (split/"\s+"/, $line)[1] would be undef
0
 
LVL 84

Expert Comment

by:ozo
ID: 24308646
if you said
my $snetpart2 =~s/"//g;
the my would create a new variable that would not contain anything that came from
print my $snetpart2 = (split/"\s+"/, $line)[1];
0
 
LVL 1

Author Comment

by:richsark
ID: 24308718
Ok, so the complete code looks like;
adding this:
my $snetpart2 = (split/"\s+"/, $line)[1];

#!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 1

Author Comment

by:richsark
ID: 24308768
If that is the case, I am still getting the bloddy EOF
 
Checking 162.2.0.0/16
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
sh: -c: line 0: unexpected EOF while looking for matching `"'
sh: -c: line 1: syntax error: unexpected end of file
0
 
LVL 84

Expert Comment

by:ozo
ID: 24308859
If what is the case?
what is in $snetpart2 when you get that error?
0
 
LVL 1

Author Comment

by:richsark
ID: 24308900
HI, Also, I cant figure out how to format the output
From this:

Subnet,Static,DHCP,Unused
10.0.0.0/8
,37,0,217
146.149.0.0/16
To this:
Subnet,Static,DHCP,Unused

10.0.0.0/8,37,0,217
146.149.0.0/16,174,0,39314
0
 
LVL 1

Author Comment

by:richsark
ID: 24308962
I used this part:
 my $snetpart2 = (split/"\s+"/, $line)[1];
             if( $snetpart2 =~ /"/ ){
             warn "\$snetpart2 i was $snetpart2\nwhen \$line was $line";
             next;  
}
Seems to work; now I get messages like:
when $line was " "  "162.2.201.0"  "N"  "Enterprise Management LAN"  "162.2.0.0"  "EMEA-"  " "  "255.255.255.0"
$snetpart2 i was   "162.2.240.0
when $line was " "  "162.2.240.0"  "N"  "Enterprise Management LAN"  "162.2.0.0"  "EMe"  " "  "255.255.255.0"
$snetpart2 i was   "162.2.241.0
when $line was " "  "162.2.241.0"  "N"  "Enterprise Management LAN"  "162.2.0.0"  "Usa-"  " "  "255.255.255.0"
Checking 162.5.0.0/16
 
What  does this mean?
warn "\$snetpart2 i was $snetpart2\nwhen \$line was $line";
Focusing on "i was" and "nwhen"

#!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];

             if( $snetpart2 =~ /"/ ){

             warn "\$snetpart2 i was $snetpart2\nwhen \$line was $line";

             next;  

} 

            # 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 84

Expert Comment

by:ozo
ID: 24309056
DB<5> $line='" "  "162.2.201.0"  "N"  "Enterprise Management LAN"  "162.2.0.0"  "EMEA-"  " "  "255.255.255.0"'

                                                                                                                                                                            DB<6> x (split/"\s+"/, $line)                                                                                
0  ''
1  '  "162.2.201.0'
2  'N'
3  'Enterprise Management LAN'
4  '162.2.0.0'
5  'EMEA-'
6  ' '
7  '255.255.255.0"'
                                                                                                                                                                            DB<7> x (split/"\s+"/, $line)[1]
0  '  "162.2.201.0'
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 24309122
"i" is a typo and "\n" is a newline
0
 
LVL 1

Author Comment

by:richsark
ID: 24309205
Ok, can you please comment on the format output above please
0
 
LVL 1

Author Comment

by:richsark
ID: 24313252
Thanks for your help Ozo !
I would of never thought of that ( at least this year )
my $snetpart2 = (split/"\s+"/, $line)[1];
            if( $snetpart2 =~ /"/ ){
            warn "\$snetpart2 i was $snetpart2\nwhen \$line was $line";
            next;  
}
 Before I close this out, is there a way I could get you to see why I cant get the format right.
I would like the output from the log-external.txt
from this:

Subnet,Static,DHCP,Unused

10.0.0.0/8
,37,0,217
146.149.0.0/16

To this:

Subnet,Static,DHCP,Unused

10.0.0.0/8,37,0,217
146.149.0.0/16,174,0,39314
I  tried to play with the line

printf $log "%s,%d,%d,%d\n", $subnet, $counts{Static}, $counts{DHCP}, $counts{Unused};

I tried this:
printf $log "%s,%d,%d,%d,%d\n", $subnet, $subnet, $counts{Static}, $counts{DHCP}, $counts{Unused};

And:

printf $log "%s,%d,%d,%d\n", $subnet, $subnet\n $counts{Static}, $counts{DHCP}, $counts{Unused};

Any thoughts?

0
 
LVL 1

Author Closing Comment

by:richsark
ID: 31577852
good work
0
 
LVL 84

Expert Comment

by:ozo
ID: 24323222
It looks like $subnet has a "\n" at the end, which is strange, since the chomp $subnet; should have removed it, and  a "\n" in  $subnet should have caused a problem for `./getsubnetlst.exe -u xx-p xx -o rich -a $subnet -t network`
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now