Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Tweak an existing script

Posted on 2009-04-09
8
Medium Priority
?
292 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
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.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
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

618 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