[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

options script

Hello
I have tried to my best ability to work around this script tht will reference my m-names.txt which contains the format of:
168.16.0.0/16
169.56.0.0/16
132.2.0.0/16
122.5.0.0/16

Then I call a cli named getzoneprof that will set the $subnet from each of the lines in the m-named.txt file

The output have lots of output, but I am only interested in a particular section:

Sark DNS 4.X Options
        Import External Updates=False
        allow-notify=Use Server Value
        allow-query=Any
        allow-transfer=Any
        allow-update=Use List
                ACL Templates=
                other=100.100.100.1
        notify=No
        zone block of named.conf=
        zone block of named.conf=forwarders {};

I need to capture what the Import External Updates= is set to, either True/False

Once found, make a report log-external-updates.txt that says

For subnet Xyx
under Sark DNS 4.X Options field, found Import External Updates is set to:TRUE/FALSE

When I run ths script I get some errors:
Name "main::out" used only once: possible typo at ext-updates.pl line 21.
Name "main::revlist" used only once: possible typo at ext-updates.pl line 6.
Use of uninitialized value $out in ref-to-glob cast at ext-updates.pl line 21

I am not an expert yet, but trying ...




#!perl -w
open(my $log, ">log-external-updates.txt") or die "Could not open log: $!\n";
 
open(my $in, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
 
foreach(@revlist) {
        next unless /(.*?)\/(.*)$/;
        my $subnet = $1;
        
        print "Checking $subnet\n";
        my $dnsoptions = `./getzoneprof -u xx-p xx-a $subnet -o rich`;
        
        next unless $dnsoptions =~ /Sark DNS 4.X ([^\r\n]*).*?Import External Updates=([^\r\n]*)/is;
        next unless $AllowUpdate =~ /(True|False)/;
        
        print $log "$subnet\n";
        print $log "Sark DNS 4.X Options field found, "
              .    "Import External Updates= $AllowUpdate\n";
 } 
 
close($out);

Open in new window

0
richsark
Asked:
richsark
  • 14
  • 6
1 Solution
 
ozoCommented:
#!perl -w
open(LOG, ">log-external-updates.txt") or die "Could not open log: $!\n";
 
open( 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 = `./getzoneprof -u xx-p xx-a $subnet -o rich`;
       
        next unless my($AllowUpdate) = $dnsoptions =~ /Import External Updates=([^\r\n]*)/is;
        next unless $AllowUpdate =~ /(True|False)/;
       
        print LOG "$subnet\n";
        print LOG "Sark DNS 4.X Options field found, "
              .    "Import External Updates= $AllowUpdate\n";
 }
 
close(LOG)
0
 
richsarkAuthor Commented:
Hi Ozo, under the section
next unless /(.*?)\/(.*)$/;
I need it to read exactly as its in the m-names.txt file one at a time
168.16.0.0/16
169.56.0.0/16
132.2.0.0/16
122.5.0.0/16

Thanks
 
 
0
 
Adam314Commented:
This line:
    next unless /(.*?)\/(.*)$/;
will skip lines that do not match the pattern "some stuff, followed by forward slash, followed by stuff, end of line".  For the lines that do match, the first stuff is saved as $1, and the second stuff is saved as $2.
0
Independent Software Vendors: 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!

 
richsarkAuthor Commented:
Ok, But I need it to pull directly from m-names.txt as is

168.16.0.0/16
169.56.0.0/16
132.2.0.0/16
122.5.0.0/16

So, your saying I need to take out that next unless statement?
0
 
richsarkAuthor Commented:
Ok, so I needs it to be like
next unless /(.*?)$/;
 
Hey... I am tryin
0
 
richsarkAuthor Commented:
Hey,... I did not try my above post, So I figured whythe heck not. And it worked !
I am proud of myself !
0
 
Adam314Commented:
This line:
    next unless /(.*?)$/;
means, skip line unless it matches the pattern "some stuff, end of line".  The original script, and what ozo posted, would call your cli for this 168.16.0.0/16 with 168.16.0.0, leaving off the /16.  What your change does is have it call your cli with the entire 168.16.0.0/16.  


Because every line will match your pattern /(.*?)$/, you don't really need to look for it.  You could just chomp the line to remove the line ending:
    chomp;
Then, in place of $subnet, just use $_.
0
 
richsarkAuthor Commented:
HI, Seems that All my responses are coming back as False. When I manually set it to True, then I  ran the perl script, It wrote False.

Perhaps since there are multiple wordings "Import External Updates" but I want to focus only under Sark DNS 4.x, see below on how many times its seen.

Zone=100.0.0.0/8
ParentAddress=
NetworkAddress=100.0.0.0
dnsServers=l S
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Any
        allow-transfer=Any
        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=Any
        allow-transfer=Any
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=allow-update {
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=};
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Any
        allow-transfer=Any
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=allow-update {
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=};
Sark DNS 4.X Options
        Import External Updates=True
                A (Host IPV4)=False
                AAAA (Host IPV6)=False
                CNAME (Canonical Name)=False
                PTR (Pointer)=False
                SRV (Server Resource Record)=Fal
                TXT (Text)=False
        allow-notify=Use Server Value
        allow-query=Any
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        notify=Use Server Value
        zone block of named.conf=allow-update {
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=
        zone block of named.conf=1
        zone block of named.conf=10..
        zone block of named.conf=169.
        zone block of named.conf=};
WINDOWS 2000 DNS Options
        aging=False
0
 
richsarkAuthor Commented:
I gave it a shot, with the below code, But as usuall I get errors

Unquoted string "r" may clash with future reserved word at ex-updates.pl line 13.
Backslash found where operator expected at ex-updates.pl line 13, near "r\"
Unquoted string "n" may clash with future reserved word at ex-updates.pl line 13.
Unquoted string "ism" may clash with future reserved word at ex-updates.pl line 13.
syntax error at ex-updates.pl line 13, near "Sark DNS 4.X = $dnsoptions =~ /Import External"
Execution of ex-updates.pl aborted due to compilation errors.

#!perl -w
open(LOG, ">log-udates-.txt") or die "Could not open log: $!\n";
 
open( IN, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
 
while( <IN> ){
        chomp;
        my $subnet = $_;
        
        print "Checking $subnet\n";
        my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $subnet -o steve`;
        
        if($dnsoptions =~ /Sark DNS 4.X = $dnsoptions =~ /Import External Updates=([^\r\n]*)/im;
        next unless $dnsoptions =~ /(True|False)/;
        
        print LOG "$subnet\n";
        print LOG "Sark DNS 4.X Options field found, "
              .    "Import External Updates= $dnsoptions\n";
 }
 
close(LOG)

Open in new window

0
 
Adam314Commented:

next unless (my ($IEU) = $dnsoptions =~ /Sark DNS 4.X Options.*?Import External Updates=(\S+)/s);
#now, $IEU contains whatever was after the first "Import External Updates" after "Sark DNS 4.X Options"

Open in new window

0
 
richsarkAuthor Commented:
Hi, so I need to put it like so?If so, I run it, but no log is created now?


#!perl -w
open(LOG, ">log-udates-.txt") or die "Could not open log: $!\n";
 
open( IN, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
 
while( <IN> ){
        chomp;
        my $subnet = $_;
        
        print "Checking $subnet\n";
        my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $subnet -o steve`;
        
        next unless (my ($IEU) = $dnsoptions =~ /Sark DNS 4.X Options.*?Import External Updates=(\S+)/s);
        next unless $dnsoptions =~ /(True|False)/;
        
        print LOG "$subnet\n";
        print LOG "Sark DNS 4.X Options field found, "
              .    "Import External Updates= $dnsoptions\n";
 }
 
close(LOG)

Open in new window

0
 
richsarkAuthor Commented:
HI, Any help?
0
 
Adam314Commented:
Get rid of this line:
    next unless $dnsoptions =~ /(True|False)/;

0
 
richsarkAuthor Commented:
I did, still a 0 byte log
0
 
Adam314Commented:
Replace line 13 with this:
my $IEU;
if($dnsoptions =~ /Sark DNS 4.X Options.*?Import External Updates=(\S+)/s) {
    $IEU = $1;
}
else {
    warn "Did not find Import External Updates for $subnet\n";
    next;
}

Open in new window

0
 
richsarkAuthor Commented:
Hi Adam, I am not sure what I am doing wrong.. I added the new code, still have a 0 bytes log.
I see it running:
Checking 169.69.107.0/24
Checking 169.69.114.0/24
Checking 169.69.115.0/24
Checking 169.69.123.0/24

#!perl -w
open(LOG, ">log-external-updates-test-4-28-2009.txt") or die "Could not open log: $!\n";
 
open( 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 = `./getzoneprof -u xx -p xx -a $subnet -o Steve`;
        
  my $IEU;
if($dnsoptions =~ /Sark DNS 4.X Options.*?Import External Updates=(\S+)/s) {
    $IEU = $1;
}
else {
    warn "Did not find Import External Updates for $subnet\n";
    next;
}
        
        print LOG "$subnet\n";
        print LOG "Sark DNS 4.X Options field found, "
              .    "Import External Updates= $AllowUpdate\n";
 } 
 
close(LOG)

Open in new window

0
 
richsarkAuthor Commented:
Ok, I changed line 24 with $dnsoptions
and now I get
Did not find Import External Updates for 10.0.0.0/8
Checking 10.0.0.0/16
Did not find Import External Updates for 10.0.0.0/16
Checking 10.2.0.0/16
Did not find Import External Updates for 10.2.0.0/16
But I know there there since I can see it when I run it manuley
0
 
Adam314Commented:
Are you sure the output of getzoneprof is how you've shown it?
0
 
richsarkAuthor Commented:
Yup,
I run it manualy as such, and its there, see below
 ./getzoneprof -u qipman -p qipman -a 10.0.0.0/8 -o steve
Sark DNS 4.X Options
        Import External Updates=True
                A (Host IPV4)=False
                AAAA (Host IPV6)=False
                CNAME (Canonical Name)=False
                PTR (Pointer)=False
                SRV (Server Resource Record)=False
                TXT (Text)=False
        allow-notify=Use Server Value
        allow-query=Any
        allow-transfer=Use Server Value
        allow-update=Use List
                ACL Templates=
                other=199.4.240.200
        notify=No
Do you think we need to add \ism to the end of the line 14
0
 
richsarkAuthor Commented:
Ok, I got it, I added  $IEU on this line
  "Import External Updates= $IEU\n"
Its all good now !
10.0.0.0/8
Sark DNS 4.X Options field found, Import External Updates= True
 
Let me do the whole script, and I will let you know
0
 
richsarkAuthor Commented:
Awesome help and knowledge
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 14
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now