Solved

Tweak an existing script

Posted on 2009-04-09
8
286 Views
Last Modified: 2012-05-06
Hello, The below script needs to report on a few different parameters

I dont need these values anymore

Sark DNS 4.X
allow-update=
ACL Templates=

The stuff I need is in the same master file we used in the script

Zone=200.200.200.0/24 ($network)

dnsServers=

I would like dnsServers= to be separated by the P ( Primary)  and S ( Secondary) in a list

so the report could look like

$network=
Primary DNS Server= ILS230.svr.sark.net
Secondary DNS Servers=app32dns2.svr.sark.net
                                          app32dns4.svr.sark



The master file from getzoneprof.exe looks like:

Zone=169.69.250.0/24
ParentAddress=169.69.0.0/16
NetworkAddress=169.69.0.0
dnsServers=ILS230.svr.sark.net P 0,app32dns1.svr.sark.net S 0,app32dns2.svr.sark.net S 0,app32dns4.svr.sark.net S 0,app32dns5.svr.sark.net S 0,app32dns6.
svr.sark.net S 0,app32am1.sark.net P 0,app32am2.sark.net S 0
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=host@hi@sark.com
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Any
        allow-transfer=Any
        allow-update=Any
        check-names=Warn
        notify=No
        zone block of named.conf=
BIND-9.X Options
        allow-notify=Use Server Value
        allow-query=Any
        allow-transfer=Any
        allow-update=Any
        notify=No
        zone block of named.conf=
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Any
        allow-transfer=Any
        allow-update=Any
        check-names=Warn
        notify=No
        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 Server Value
        notify=Use Server Value
        zone block of named.conf=




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]*)/ism;
        my $Other=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?other\s*=\s*([^\r\n]*)/ism;
        $ACLTemplate='*none*' unless $ACLTemplate;
        $Other='*none*' unless $Other;
        
        next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|Use 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);

Open in new window

0
Comment
Question by:richsark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 1

Author Comment

by:richsark
ID: 24109809
Hi, Any ideas on how to tweak this script?
0
 
LVL 1

Author Comment

by:richsark
ID: 24111463
Here is my attempt, but of course it does not 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`;
        
        next unless $dnsoptions =~ /dnsServers ([^\r\n]*).*?S O =([^\r\n]*)/is;
        my ($Option, $Secondary) = ($1, $2);
        my $Primary=$1 if $dnsoptions =~ /dnsServers*?P =\s*([^\r\n]*)/ism;
        my $Secondary=$1 if $dnsoptions =~ /dnsServers*?S O*?other\s*=\s*([^\r\n]*)/ism;
                
        next unless $Secondary =~ /(S O)/;
         
        print $out "$network\n";
        print $out "Primary Name Server$Primary=, "
              .    "Secondary DNS Server=$Secondary  "
              .    "and other=$Secondary\n";
} 
 
close($out);

Open in new window

0
 
LVL 25

Expert Comment

by:lwadwell
ID: 24112358
Hi richsark,

I have had an attempt at mocking up something that may help you.  See below.  I made some assumptions that in the list of dbSservers, the trailing P 0 indicated a primary server and S 0 indicated a secondary one.

lwadwell
if ($dnsoptions =~ /dnsServers=(.*?)\n/) {
	my $dnsservers = $1;
	print $dnsservers . "\n";
	my @servers = split(/,/,$dnsservers);
	my @primarydns;
	my @secondarydns;
	foreach my $dns ( @servers ) {
		if ( $dns =~ /^(.*)\s+P\s+\d$/ ) {
			push(@primarydns,$1);
		} elsif ( $dns =~ /^(.*)\s+S\s+\d$/ ) {
			push(@secondarydns,$1);
		}
	}
	print "Primary DNS = @primarydns\n";
	print "Secondary DNS = @secondarydns\n";
}

Open in new window

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!

 
LVL 1

Author Comment

by:richsark
ID: 24112387
Hi,

Your assumption is correct,

I also need to add the Network address in variable $network to the report, can that be added to the print statement?

What about the top part, do I just add it to your script? I need them to work together to get the results

my @revlist = `./getrevlist.exe -u xx -p xx -o Orig`;
 
open(my $out, ">final-results.txt") or die "Could not open output:

foreach(@revlist) {
        next unless /,(.*)$/;
        my $network = $1;
       
        print "Checking $network\n";
        my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;
0
 
LVL 25

Accepted Solution

by:
lwadwell earned 500 total points
ID: 24112611
something like below perhaps ...
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`;
        
    if ($dnsoptions =~ /dnsServers=(.*?)\n/) {
	my $dnsservers = $1;
	print $dnsservers . "\n";
	my @servers = split(/,/,$dnsservers);
	my @primarydns;
	my @secondarydns;
	foreach my $dns ( @servers ) {
            if ( $dns =~ /^(.*)\s+P\s+\d$/ ) {
		push(@primarydns,$1);
	    } elsif ( $dns =~ /^(.*)\s+S\s+\d$/ ) {
		push(@secondarydns,$1);
	    }
	}
	my $Secondary = shift(@secondarydns);
        print $out "$network\n";
        print $out "Primary Name Server=@primarydns "
              .    "Secondary DNS Server=$Secondary  "
              .    "and other=@secondarydns\n";
}
} 
 
close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24116199
HI,

I ran the script, the final-results.txt has weird characters

20008
rmr aeS
0
 
LVL 1

Author Closing Comment

by:richsark
ID: 31568499
Thanks ! good work
0
 
LVL 1

Author Comment

by:richsark
ID: 24117618
Disregard my last comment, It was my fault. The script worked perfectly.
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

730 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