help with disection script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help with disection script
# 1  
Old 05-22-2009
help with a disection script to report contents

Hi all !,

I have this nice script that was created by someone else. and was looking for a different opinions on this forum.

Code:
#!perl -w
use strict;
 
my %all_ips;
my %all_zones;
my %zone_ips;
while (<>) {
    next unless /^zone\s+\"(.*)\"/;
    my $zone = $1;
    while (<>) {
        print "Warn: allow-update not found in $zone\n" if /^\}\;/;
        next unless /allow-update\s*\{\s*(.*)/;
        my $ips = $1;
        if ($ips =~ /none/i) {
            print "Warn: zone $zone contains no IPs (none)\n";
            last;
        }
        while (<>) {
            if (/(.*)\}\;/) {
                $ips .= $1;
                if ($ips =~ /none/i) {
                    print "Warn: $zone contains no IPs (none)\n";
                    last;
                }
                my %seen;
                my @ips = grep {!$seen{$_}++} split(/[\s\;]+/, $ips);
                foreach (@ips) {
                    $all_ips{$_}++;
                    $zone_ips{$_} .= " $zone";
                }
                $all_zones{$zone} = [ @ips ];
                last;
            }
            $ips .= $_;
        }
        last;
    }
}
 
my $num_zones = keys(%all_zones);
print "\nCounted ".$num_zones." zones.\n";
exit unless $num_zones;
 
print "\nThey are:\n";
print join("\n", keys %all_zones)."\n";
 
my @in_all;
my @not_all;
foreach (sort keys %all_ips) {
    if ($all_ips{$_}==$num_zones) {
        push @in_all, $_;
    }
    else {
        push @not_all, $_;
    }
}
 
if (@in_all) {
    print "\nThe following IP's appear in all $num_zones zones:\n";
    print join("\n", @in_all)."\n";
}
 
if (@not_all) {
    print "\nThe following IP's do not appear in all zones:\n";
    print "\nIP shown with zones it's found in:\n";
    foreach (@not_all) {
        print $_." $zone_ips{$_}\n";
    }
}

But the output is not quite what I need: right now it looks like this: ( keep in mind this is not the entire output, just an excerpt.

Warn: allow-update not found in qa.sarkie.net
Warn: zone dhcp.sark.com contains no IPs (none)
Warn: allow-update not found in 127.in-addr.arpa

Counted 4 zones.

They are:
wes.sark.com
fre.sark.com
nrm.sark.com
us.ad.sark.com

The following IP's appear in all 4 zones:
10.128.1.54
133.180.204.54
133.180.204.55
133.85.117.224

IP's shown with zones it's found in:
10.128.1.53 sarkie.com aus.sarkie.com col.sarkie.com dal.sarkie.com wes.sarkie.com wil.sarkie.com wilm.sarkie.com us.ad.sarkie.com qa.richard.net spr.sarkie.com htr.sarkie.com nor.sarkie.com nrm.sarkie.com elg.sarkie.com fdr.sarkie.com ven.sarkie.com ext.sarkie.com fre.sarkie.com car.sarkie.com het.sarkie.com heathrow.sarkie.com cha.sarkie.com net.sarkie.com lvs.sarkie.com tst.ad.sarkie.com mec.sarkie.com 127.in-addr.arpa 168.in-addr.arpa 192.in-addr.arpa

10.128.2.53 sarkie.com aus.sarkie.com col.sarkie.com dal.sarkie.com wes.sarkie.com wil.sarkie.com wilm.sarkie.com us.ad.sarkie.com qa.richard.net spr.sarkie.com htr.sarkie.com nor.sarkie.com nrm.sarkie.com elg.sarkie.com fdr.sarkie.com ven.sarkie.com ext.sarkie.com fre.sarkie.com car.sarkie.com het.sarkie.com heathrow.sarkie.com cha.sarkie.com net.sarkie.com lvs.sarkie.com tst.ad.sarkie.com mec.sarkie.com 127.in-addr.arpa 168.in-addr.arpa 192.in-addr.arpa

10.144.1.53 sarkie.com aus.sarkie.com col.sarkie.com dal.sarkie.com wes.sarkie.com wil.sarkie.com wilm.sarkie.com us.ad.sarkie.com qa.richard.net spr.sarkie.com htr.sarkie.com nor.sarkie.com nrm.sarkie.com elg.sarkie.com fdr.sarkie.com ven.sarkie.com ext.sarkie.com fre.sarkie.com car.sarkie.com het.sarkie.com heathrow.sarkie.com cha.sarkie.com net.sarkie.com lvs.sarkie.com tst.ad.sarkie.com mec.sarkie.com 127.in-addr.arpa 168.in-addr.arpa 192.in-addr.arpa

Its still hard to pinpoint what IP's and zones go to what.

so, this is my thought on a better output

Lets say I have these zones which the scripts finds just fine

ad.sark123.com
aus.rich.com
sark.com

under each zone we have allow-update with many IP addresses

What I need to do is find out if any or all of the IP's are the same in each zone or not.

So my thinking is to have a report like so

from the 30 zones found, all these zones ZYZ.. have the same IP addresses except for zones XYZ. The zone are..., and the IP addresses are...


Could someone help me tweak this to make it a lot easier to figure out what zones have the same IP's and what zones do not as per my example above.

Also, the master file this is run against is below: ( just an excerpt)

I have a named.conf file that looks like this, small excerpt of the real file)

Code:
controls {
        inet 127.0.0.1 allow { localhost; } keys { "rndc-key"; };
};

key "rndc-key" {
        algorithm "hdtc-m65";
        secret "helpme="; 
};

acl "SRS" {
                        121.118.14.107;
                        187.118.215.112;
                        153.118.255.200;
                };



acl "SRSHUTYDNS" {
                        200.180.12.100;
                        100.200.138.82;
                        190.121.100.68;
                        30.129.21.81;
                };
options {
        directory "/var2/named";
        qddns
        {
                edup
                {
                        my-ip 200.118.14.102;
                        message-service-ip 127.0.0.1;
                        message-service-port 4468;
                        org-id 200;
                };
        };
        forwarders {
                   120.180.238.53;  // SRS5  
                   120.180.174.53;  // SRS4  
                   120.180.254.53;  // SRSdns6  
        };
        forward only;
        minimal-responses yes;
        allow-transfer { "SRSCARD"; "SRSHUTYDNS"; }; // test
        allow-query { any; };
        notify yes;
        version "";
};
 
logging {
        channel xfer_info {
                file "log/xfer.log" versions 5 size 5m;
                print-time yes;
                print-severity yes;
                severity info;
        };
        category xfer-in {xfer_info;};
        category xfer-out {xfer_info;};
};
 
#include "db.INCLUDE.logging.query";
include "db.INCLUDE.forwarders-for-sark";
 

zone "sark.com" in {
        type master;
        file "db.sark.com";
        allow-update {  211.118.95.190;211.118.66.65;211.118.49.164;211.118.4.246;211.118.4.165;211.118.4.162;
                         211.118.255.102;211.118.246.12;211.118.215.102;211.118.212.210;211.118.19.190;211.118.19.102;
                         211.118.14.8;211.118.14.102;211.118.116.198;167.85.70.12;167.85.16.154;167.85.117.224;12.128.1.54;
                         120.180.204.54;120.180.204.55;211.118.31.229; 167.85.102.1; 167.85.102.2;120.180.254.55;120.180.254.54;
        12.128.1.53;12.128.2.53;12.144.1.53;12.144.2.53;12.148.1.53;12.148.2.53;
        12.160.1.53;12.160.2.53;199.86.40.148;199.86.40.20;199.86.40.220;199.86.40.28;
        199.86.40.36;199.86.40.68;199.86.40.76;199.86.40.84;
        };
};

zone "ad.sark123.com" in {
        type master;
        file "db.ad.sark123.com";
        allow-update {  211.118.95.190;211.118.66.65;211.118.49.164;211.118.4.246;211.118.4.165;211.118.4.162;
                                211.118.255.102;211.118.246.12;211.118.215.102;211.118.212.210;211.118.19.190;211.118.19.102;
                                211.118.14.8;211.118.14.102;211.118.116.198;167.85.70.12;167.85.16.154;167.85.117.224;12.128.1.54;
                                120.180.204.54;120.180.204.55;211.118.31.229;120.180.254.55;120.180.254.54;
        };
        zddns
        {
                edup rr-types { "A"; "CNAME"; "PTR"; "SRV"; };
        };
};

zone "aus.rich.com" in {
        type master;
        file "db.aus.rich.com";
        allow-update {  211.118.95.190;211.118.66.65;211.118.49.164;211.118.4.246;211.118.4.165;211.118.4.162;
                         211.118.255.102;211.118.246.12;211.118.215.102;211.118.212.210;211.118.19.190;211.118.19.102;
                         211.118.14.8;211.118.14.102;211.118.116.198;167.85.70.12;167.85.16.154;167.85.117.224;12.128.1.54;
                         120.180.204.54;120.180.204.55;211.118.31.229;120.180.254.55;120.180.254.54;
        12.128.1.53;12.128.2.53;12.144.1.53;12.144.2.53;12.148.1.53;12.148.2.53;
        12.160.1.53;12.160.2.53;199.86.40.148;199.86.40.20;199.86.40.220;199.86.40.28;
        199.86.40.36;199.86.40.68;199.86.40.76;199.86.40.84;
        };
};


Last edited by otheus; 05-25-2009 at 11:54 AM.. Reason: code tags, spelling correction
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question