Solved

Tweak an existing script

Posted on 2009-04-09
8
283 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

932 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

9 Experts available now in Live!

Get 1:1 Help Now