?
Solved

Tweak an existing script

Posted on 2009-04-09
8
Medium Priority
?
294 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

840 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