cant get perl to pull information right

Hello,
I cant get the perl script to pull the information from

Sark DNS 4.X Options
ACL Templates=
and other=

Can someone look at the script to see why and fix it please.

FYI..Under Sark DNS 4.x ACL Templates= and other= has an indent/tab, not sure if thats the reason my the script does not work??

I spent 3 days on it. I only need it from Sark DNS 4.X Options, If it appears anywhere else, I dont care. just in Sark DNS 4.X Options

(output from final-results.txt)
2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=*none* and other=*none*

When I manually run it, it clearly shows its under "Sark DNS 4.x:

Zone=2.0.0.0/8
ParentAddress=
NetworkAddress=2.0.0.0
dnsServers=S230.svr.sark.net P 0,srsdns1.svr.sark.net S 0,txrtp1dns.svr.sark.net S 0,txtp2dns.svr.sark.net S 0,srsdnh2.svr.sark.net S 0,es
ne1.svr.sark.net S 0,azrp1dns.svr.sark.net S 0,artp2dns.svr.sark.net S 0,rtp1dns.svr.sark.net S 0,ohrtp2dns.svr.sark.net S 0,inrtp1dns.svr.
nkone.net S 0,irtp2dns.svr.sark.net S 0,ilrtp2dns.svr.sark.net S 0,ilrtp1dns.svr.sark.net S 0,esfdns2.svr.sark.net S 0,mirtpdns.svr.sark.net
0,mirp2dns.svr.sark.net S 0,witp1dns.svr.sark.net S 0,wirtpdns.svr.sark.net S 0,lartp1dns.svr.sark.net S 0,uxns3.cmg.sark.net S 0
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@sark.net
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
BIND-9.X Options
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=DMYBP;JTESF
                other=3.3.3.3
        notify=Use Server Value
        zone block of named.conf=
WINDOWS 2000 DNS Options
        aging=False
        allow-transfer=Use List
                List=
        allow-update=No
        no-refresh-interval=0
        notify=Use List
                List=
        refresh-interval=0
        zone-options=

Here is the below code;

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;
 
open(my $out, ">final-results.txt") or die "Could not open output: $!\n";
 
foreach(@revlist) {
        next unless /,(.*)$/;
        my $network = $1;
        
        print "Checking $network\n";
        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;
        
        next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?allow-update=([^\r\n]*)/is;
        my ($Option, $AllowUpdate) = ($1, $2);
        my $ACLTemplate=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?ACL Templates\s*=\s*([^\r\n]*)/sm;
        my $Other=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?other\s*=\s*([^\r\n]*)/sm;
        $ACLTemplate='*none*' unless $ACLTemplate;
        $Other='*none*' unless $Other;
        
        next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|ACL Templates|other|localnets)/;
        
        print $out "$network\n";
        print $out "Under Sark DNS 4.X Options field found, "
              .    "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate "
              .    "and other=$Other\n";
} 
 
close($out);

Untested.....

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;
open(my $out, ">final-results.txt") or die "Could not open output: $!\n";
foreach(@revlist) {
   next unless /,(.*)$/;
   my $network = $1;
   print "Checking $network\n";
   my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;
   my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ('*none*', '*none*', '*none*', '*none*');
   my $flag = 0;
   my @dnsoptions = split(/\r?\n/,$dnsoptions);
   foreach my $line (@dnsoptions){
      last if $flag == 2;
      if ($flag == 1) {
         if ($line =~ /^\s*allow-update=([^\r\n]+)/) {
            $AllowUpdate = $1;
         }
         elsif ($line =~ /^\s*ACL Templates=([^\r\n]+)/) {
            $ACLTemplate = $1;
         }
         elsif ($line =~ /^\s*other=([^\r\n]+)/) {
            $Other = $1;
         }
         elsif ($line =~ /^[A-Z]/) {
            $flag = 2;
         }
      }
      elsif ($line =~ /^Sark DNS 4.X ([^\r\n]+)/) {
         $Option = $1;
         $flag = 1;
      }
   }
   print $out "$network\n";
   print $out "Under Sark DNS 4.X Options field found, ",
              "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate ",
              "and other=$Other\n";
}

Ask questions if necessary

HI, Still no luck, this is the result's.

2.0.0.0/8
Sark DNS 4.X Options field found, allow-update is set to *none* with the values Template Name=*none* and other=*none*

Still missing the values under Sark DNS 4.x

allow-update=
ACL Templates=
other=

Sark DNS 4.X Options
Import External Updates=False
allow-notify=Use Server Value
allow-query=Use Server Value
allow-transfer=Use Server Value
allow-update=Use List
ACL Templates=DMYBP;JTESF
other=3.3.3.3
notify=Use Server Value
zone block of named.conf=

FYI..Also, allow-update= can have one of many variables as my previous code, Need that incorporated.

Any|None|Use Server Value|Use List|localhost|ACL Template|other|localnets

I ask this, because I did not see it in your code.

Thanks

any help is appericated.

HI, I hate to nag, but I find it interesting that there is no comments on this.

Please let me know what more you guys need to get this resolved.

Thanks

Is the data you posted the output stored in $dnsoptions from this line of your code?

my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

If so, the code I posted works for me. I can't test your entire script, namely this part of it:

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;
 
open(my $out, ">final-results.txt") or die "Could not open output: $!\n";
 
foreach(@revlist) {
        next unless /,(.*)$/;
        my $network = $1;
        
        print "Checking $network\n";

I used the data you posted as dummy data stored in $dnsoptions, like so:

   my $dnsoptions = do {local $/; <DATA>};
   my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ('*none*', '*none*', '*none*', '*none*');
   my $flag = 0;
   my @dnsoptions = split(/\r?\n/,$dnsoptions);
   foreach my $line (@dnsoptions){
      last if $flag == 2;
      if ($flag == 1) {
         if ($line =~ /^\s*allow-update=([^\r\n]+)/) {
            $AllowUpdate = $1;
         }
         elsif ($line =~ /^\s*ACL Templates=([^\r\n]+)/) {
            $ACLTemplate = $1;
         }
         elsif ($line =~ /^\s*other=([^\r\n]+)/) {
            $Other = $1;
         }
         elsif ($line =~ /^[A-Z]/) {
            $flag = 2;
         }
      }
      elsif ($line =~ /^Sark DNS 4.X ([^\r\n]+)/) {
         $Option = $1;
         $flag = 1;
      }
   }
   print "$network\n";
   print "Under Sark DNS 4.X Options field found, ",
         "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate ",
         "and other=$Other\n";

__DATA__
Zone=2.0.0.0/8
ParentAddress=
NetworkAddress=2.0.0.0
dnsServers=S230.svr.sark.net P 0,srsdns1.svr.sark.net S 0,txrtp1dns.svr.sark.net S 0,txtp2dns.svr.sark.net S 0,srsdnh2.svr.sark.net S 0,es
ne1.svr.sark.net S 0,azrp1dns.svr.sark.net S 0,artp2dns.svr.sark.net S 0,rtp1dns.svr.sark.net S 0,ohrtp2dns.svr.sark.net S 0,inrtp1dns.svr.
nkone.net S 0,irtp2dns.svr.sark.net S 0,ilrtp2dns.svr.sark.net S 0,ilrtp1dns.svr.sark.net S 0,esfdns2.svr.sark.net S 0,mirtpdns.svr.sark.net
0,mirp2dns.svr.sark.net S 0,witp1dns.svr.sark.net S 0,wirtpdns.svr.sark.net S 0,lartp1dns.svr.sark.net S 0,uxns3.cmg.sark.net S 0
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@sark.net
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
BIND-9.X Options
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=DMYBP;JTESF
                other=3.3.3.3
        notify=Use Server Value
        zone block of named.conf=
WINDOWS 2000 DNS Options
        aging=False
        allow-transfer=Use List
                List=
        allow-update=No
        no-refresh-interval=0
        notify=Use List
                List=
        refresh-interval=0
        zone-options=

the output is:

Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=DMYBP;JTESF and other=3.3.3.3

HI, so I am confused why its not working??

Any ideas?

So your code ran like this, assuming that my input file is named rich.txt

#my @revlist = `getrevzonelst -u Xx-p Xx-o Orig`;
#open(my $out, ">final-results.txt") or die "Could not open output: $!\n";
foreach(@revlist) {
   next unless /,(.*)$/;
   my $network = $1;
#   print "Checking $network\n";
   my $dnsoptions = `rich.txt`;
   my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ('*none*', '*none*', '*none*', '*none*');
   my $flag = 0;
   my @dnsoptions = split(/\r?\n/,$dnsoptions);
   foreach my $line (@dnsoptions){
      last if $flag == 2;
      if ($flag == 1) {
         if ($line =~ /^\s*allow-update=([^\r\n]+)/) {
            $AllowUpdate = $1;
         }
         elsif ($line =~ /^\s*ACL Templates=([^\r\n]+)/) {
            $ACLTemplate = $1;
         }
         elsif ($line =~ /^\s*other=([^\r\n]+)/) {
            $Other = $1;
         }
         elsif ($line =~ /^[A-Z]/) {
            $flag = 2;
         }
      }
      elsif ($line =~ /^Sark DNS 4.X ([^\r\n]+)/) {
         $Option = $1;
         $flag = 1;
      }
   }
   print $out "$network\n";
   print $out "Under Sark DNS 4.X Options field found, ",
              "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate ",
              "and other=$Other\n";
}

Assuming the contents of rich.txt get stored in the scalar $dnsoptions, yes. But the code you have will not do that. Backtiks run applications and return results, but they do not open files and read them into a scalar.

Can you do me a favor and paste what your did and your complete code please

I already did that, here it is again:

   my $dnsoptions = do {local $/; <DATA>};
   my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ('*none*', '*none*', '*none*', '*none*');
   my $flag = 0;
   my @dnsoptions = split(/\r?\n/,$dnsoptions);
   foreach my $line (@dnsoptions){
      last if $flag == 2;
      if ($flag == 1) {
         if ($line =~ /^\s*allow-update=([^\r\n]+)/) {
            $AllowUpdate = $1;
         }
         elsif ($line =~ /^\s*ACL Templates=([^\r\n]+)/) {
            $ACLTemplate = $1;
         }
         elsif ($line =~ /^\s*other=([^\r\n]+)/) {
            $Other = $1;
         }
         elsif ($line =~ /^[A-Z]/) {
            $flag = 2;
         }
      }
      elsif ($line =~ /^Sark DNS 4.X ([^\r\n]+)/) {
         $Option = $1;
         $flag = 1;
      }
   }
   print "$network\n";
   print "Under Sark DNS 4.X Options field found, ",
         "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate ",
         "and other=$Other\n";

__DATA__
Zone=2.0.0.0/8
ParentAddress=
NetworkAddress=2.0.0.0
dnsServers=S230.svr.sark.net P 0,srsdns1.svr.sark.net S 0,txrtp1dns.svr.sark.net S 0,txtp2dns.svr.sark.net S 0,srsdnh2.svr.sark.net S 0,es
ne1.svr.sark.net S 0,azrp1dns.svr.sark.net S 0,artp2dns.svr.sark.net S 0,rtp1dns.svr.sark.net S 0,ohrtp2dns.svr.sark.net S 0,inrtp1dns.svr.
nkone.net S 0,irtp2dns.svr.sark.net S 0,ilrtp2dns.svr.sark.net S 0,ilrtp1dns.svr.sark.net S 0,esfdns2.svr.sark.net S 0,mirtpdns.svr.sark.net
0,mirp2dns.svr.sark.net S 0,witp1dns.svr.sark.net S 0,wirtpdns.svr.sark.net S 0,lartp1dns.svr.sark.net S 0,uxns3.cmg.sark.net S 0
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@sark.net
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
BIND-9.X Options
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=DMYBP;JTESF
                other=3.3.3.3
        notify=Use Server Value
        zone block of named.conf=
WINDOWS 2000 DNS Options
        aging=False
        allow-transfer=Use List
                List=
        allow-update=No
        no-refresh-interval=0
        notify=Use List
                List=
        refresh-interval=0
        zone-options=

the code uses the __DATA__ filehandle to input your sample data and store it in the scalar $dnsoptions.

Ok, I did the same code as you did, and did not get the expected results

E:\rich\cli>perl adl5.pl

Under Sark DNS 4.X Options field found, allow-update is set to *none* with the values Template Name=*none* and other=*none*

my $dnsoptions = do {local $/; rich.txt};
   my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ('*none*', '*none*', '*none*', '*none*');
   my $flag = 0;
   my @dnsoptions = split(/\r?\n/,$dnsoptions);
   foreach my $line (@dnsoptions){
      last if $flag == 2;
      if ($flag == 1) {
         if ($line =~ /^\s*allow-update=([^\r\n]+)/) {
            $AllowUpdate = $1;
         }
         elsif ($line =~ /^\s*ACL Templates=([^\r\n]+)/) {
            $ACLTemplate = $1;
         }
         elsif ($line =~ /^\s*other=([^\r\n]+)/) {
            $Other = $1;
         }
         elsif ($line =~ /^[A-Z]/) {
            $flag = 2;
         }
      }
      elsif ($line =~ /^Sark DNS 4.X ([^\r\n]+)/) {
         $Option = $1;
         $flag = 1;
      }
   }
   print "$network\n";
   print "Under Sark DNS 4.X Options field found, ",
         "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate ",
         "and other=$Other\n";

OK. The problem is this line:

my $dnsoptions = do {local $/; rich.txt};

rich.txt is a filename, not a filehandle.

Do this:

#!/usr/bin/perl
$network = '???';
my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;
print $dnsoptions;

change this to whatever value $network will need to run the code:

$network = '???';

post back what gets printed

ok

E:\rich\cli>unix.pl

Zone=2.0.0.0/8
ParentAddress=
NetworkAddress=2.0.0.0
dnsServers=Iii0S230.svr.sark.net P 0,app1dns90.svr.sark.net S 0,txrtp1dns.svr.sark.net S 0,txrtp2dns.svr.sark.net S 0,app1dns2.svr.sark.net S 0,esfd
ns1.svr.sark.net S 0
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@sark.net
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
BIND-9.X Options
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=B1DMZBP
                other=3.3.3.3
        notify=Use Server Value
        zone block of named.conf=
WINDOWS 2000 DNS Options
        aging=False
        allow-transfer=Use List
                List=
        allow-update=No
        no-refresh-interval=0
        notify=Use List
                List=
        refresh-interval=0
        zone-options=

E:\rich\cli>

Code is

#!/usr/bin/perl
$network = '2.0.0.0/8';
my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $network -o Orig`;
print $dnsoptions;

OK, if this test works then the code I posted previously should work:

#!/usr/bin/perl
$network = '2.0.0.0/8';
my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $network -o Orig`;
#print $dnsoptions;
@dnsoptions = split(/\r?\n/, $dnsoptions);
print "$_\n" for @dnsoptions;

That should print the same exact thing as previously. If it does this should work:

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;
open(my $out, ">final-results.txt") or die "Could not open output: $!\n";
foreach(@revlist) {
   next unless /,(.*)$/;
   my $network = $1;
   print "Checking $network\n";
   my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;
   my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ('*none*', '*none*', '*none*', '*none*');
   my $flag = 0;
   my @dnsoptions = split(/\r?\n/,$dnsoptions);
   foreach my $line (@dnsoptions){
      last if $flag == 2;
      if ($flag == 1) {
         if ($line =~ /^\s*allow-update=([^\r\n]+)/) {
            $AllowUpdate = $1;
         }
         elsif ($line =~ /^\s*ACL Templates=([^\r\n]+)/) {
            $ACLTemplate = $1;
         }
         elsif ($line =~ /^\s*other=([^\r\n]+)/) {
            $Other = $1;
         }
         elsif ($line =~ /^[A-Z]/) {
            $flag = 2;
         }
      }
      elsif ($line =~ /^Sark DNS 4.X ([^\r\n]+)/) {
         $Option = $1;
         $flag = 1;
      }
   }
   print $out "$network\n";
   print $out "Under Sark DNS 4.X Options field found, ",
              "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate ",
              "and other=$Other\n";
}

If it does not work I don't know why. My guess is that getzoneprof.exe may not be returning data (or the same data) for every network you are checking.

What happened? No love?

sorry, I bang my head all day yesterday and passed out. I am trying now

OK tried this:

#!/usr/bin/perl
$network = '2.0.0.0/8';
my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $network -o Orig`;
#print $dnsoptions;
@dnsoptions = split(/\r?\n/, $dnsoptions);
print "$_\n" for @dnsoptions;
Got the output as expected.

When I ran the full code, I get nothing !

2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to *none* with the values Template Name=*none* and other=*none*
4.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to *none* with the values Template Name=*none* and other=*none*

When I ran this manually.
./getzoneprof -u Xx -p Xx -a $network -o Orig

I got this output as expected

2.in-addr.arpa,2.0.0.0/8
4.in-addr.arpa,4.0.0.0/8

Since we have next unless /,(.*)$/;

I am only interested in stuff after the ","

I still dont know why it ain't working !

Hi Kevin, I think I got it !

I added 'ism' to this line

elsif ($line =~ /^Sark DNS 4.X ([^\r\n]+)/ism) {

ran your code and got....

2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=EXCHANGESVR;B1DMZBP and other=100.100.100.1

Is this possible?