Solved

script not finding entire string

Posted on 2011-03-21
15
186 Views
Last Modified: 2012-06-27
Hi guys,

I am working with a perl script that I feed to a file. Then it creates an output

I noticed that values that have multiple IP address dont get captured.

In the master file I have:

};

zone "_msdcs.cvve.foo.edu" in {
      type master;
      file "db.msdcs.cvve.foo.edu";
      allow-update { 128.163.234.17; };
      allow-query { Any; };
      allow-transfer { 128.163.1.6; 128.163.3.10; 128.163.234.17; };
      notify no;
      check-names Ignore;
};

The output I get;

zone _msdcs.cvve.foo.edu allow_update="[128.163.234.17]"
zone _msdcs.cvve.foo.edu allow_transfer="[128.163.1.6]"

as you can see, allow_transfer should of looked like this:

zone _msdcs.cvve.foo.edu allow_transfer="[128.163.1.6,128.163.3.10,128.163.234.17]"

I will post the script on the next thread.

Thanks in advance for you help !

Rich
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
  • 9
  • 6
15 Comments
 
LVL 1

Author Comment

by:richsark
ID: 35182730
See code below:

I cant seem to understand why for allow_transfer is only showing 1 IP address on some??

Is it because one that are listed as /16 is screwing up the output?

};

zone "_msdcs.as.foo.edu" in {
      type master;
      file "db._msdcs.as.foo.edu";
      allow-update { 128.163.119.96;128.163.119.95;128.163.119.94;128.163.119.93;128.163.119.103; };
      allow-query { Any; };
      allow-transfer { 128.163/16; };
      notify no;
};

Thanks.
#!/usr/bin/perl

use strict;
use warnings;

my ($zone, $allow_update, $allow_xfer);

while (<>) {
    chomp;
    if (/^\s*zone\s*"([^"]+)"/) {
        if ($zone and $allow_update) {
            $allow_update =~ s{;\s*$}{};
            print "$zone allow_update=\"[$allow_update]\"\n"
        }
        if ($zone and $allow_xfer) {
            $allow_xfer =~ s{;\s*$}{};
            $allow_xfer =~ s{;\s*}{, }g;
            print "$zone allow_transfer=\"[$allow_xfer]\"\n";
        }
        $zone = "zone $1";
        $allow_update = '';
        $allow_xfer = '';
    }
    if (/^\s*allow-update\s*{\s*\w+/../}/) {
        if (/^\s*allow-update\s*{\s*(\S+)/) {
            $allow_update = $1;
            $allow_update = '' if ($allow_update eq 'key');
        } elsif (not /\bkey\b/ and /^\s*([^;]+;)/) {
            $allow_update .= ($allow_update ? ' ' : '') . $1;
        }
    }
    if (/^\s*allow-transfer\s*{\s*\S+/../}/) {
        if (/^\s*allow-transfer\s*{\s*(\S+)/) {
            $allow_xfer = $1;
            $allow_xfer =~ s{"}{}g;
        }
    }
}
if ($zone and $allow_update) {
    $allow_update =~ s{;\s*$}{};
    print "$zone allow_update=\"[$allow_update]\"\n";
}
if ($zone and $allow_xfer) {
    $allow_xfer =~ s{;\s*$}{};
    $allow_xfer =~ s{;\s*}{, }g;
    print "$zone allow_transfer=\"[$allow_xfer]\"\n";
}

Open in new window

0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35182755
Generally, it would be something like this to capture the addresses:

$line =~ m{allow-transfer\s*{\s*(\d[\d\.;]+?);\s*};
$xfer_addr = $1;

I'll look at your script when it is posted...
0
 
LVL 1

Author Comment

by:richsark
ID: 35182786
Hi wilcoxon,

Script posted.
0
Technology Partners: 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 26

Expert Comment

by:wilcoxon
ID: 35182838
This should fix it...
#!/usr/bin/perl

use strict;
use warnings;

my ($zone, $allow_update, $allow_xfer);

while (<>) {
    chomp;
    if (/^\s*zone\s*"([^"]+)"/) {
        if ($zone and $allow_update) {
            $allow_update =~ s{;\s*$}{};
            $allow_update =~ s{;\s*}{, }g;
            print "$zone allow_update=\"[$allow_update]\"\n"
        }
        if ($zone and $allow_xfer) {
            $allow_xfer =~ s{;\s*$}{};
            $allow_xfer =~ s{;\s*}{, }g;
            print "$zone allow_transfer=\"[$allow_xfer]\"\n";
        }
        $zone = "zone $1";
        $allow_update = '';
        $allow_xfer = '';
    }
    if (/^\s*allow-update\s*{\s*\w+/../}/) {
        if (/^\s*allow-update\s*{\s*(\S+)/) {
            $allow_update = $1;
            $allow_update = '' if ($allow_update eq 'key');
        } elsif (not /\bkey\b/ and /^\s*([^;]+;)/) {
            $allow_update .= ($allow_update ? ' ' : '') . $1;
        }
    }
    if (/^\s*allow-transfer\s*{\s*\S+/../}/) {
        if (/^\s*allow-transfer\s*{\s*(\S[\/\w\d\.;\s]+?);\s*}/) {
            $allow_xfer = $1;
            $allow_xfer =~ s{"}{}g;
        }
    }
}
if ($zone and $allow_update) {
    $allow_update =~ s{;\s*$}{};
    $allow_update =~ s{;\s*}{, }g;
    print "$zone allow_update=\"[$allow_update]\"\n";
}
if ($zone and $allow_xfer) {
    $allow_xfer =~ s{;\s*$}{};
    $allow_xfer =~ s{;\s*}{, }g;
    print "$zone allow_transfer=\"[$allow_xfer]\"\n";
}

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 35182898
Yup, That did it

I see you modified line 33, is that right?

if (/^\s*allow-transfer\s*{\s*(\S[\/\w\d\.;\s]+?);\s*}/) {
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35182933
Yep.  That was the important change.  The only other changes I made was to make output spacing a little nicer (adding lines 13 and 42 - similar to what was already there for $allow_xfer).
0
 
LVL 1

Author Comment

by:richsark
ID: 35182968
Oh... Some lines have text in them for allow transfer and allow update, I need that as well.

Then I can bring to xcel and do a find replace on the name and convert to IP's

};

zone "worldof.org" in {
      type master;
      file "db.worldof.org";
      allow-update { None; };
      allow-query { Any; };
      allow-transfer { "blesstransfers"; };
      notify no;
};
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 35182997
just add " inside the char class at line 34.  It already allowed words (but wasn't allowing quotes).

        if (/^\s*allow-transfer\s*{\s*(\S["\/\w\d\.;\s]+?);\s*}/)
0
 
LVL 1

Assisted Solution

by:richsark
richsark earned 0 total points
ID: 35183055
Ok, I see,

Final code is below if you concur

Thanks !
#!/usr/bin/perl

use strict;
use warnings;

my ($zone, $allow_update, $allow_xfer);

while (<>) {
    chomp;
    if (/^\s*zone\s*"([^"]+)"/) {
        if ($zone and $allow_update) {
            $allow_update =~ s{;\s*$}{};
            $allow_update =~ s{;\s*}{, }g;
            print "$zone allow_update=\"[$allow_update]\"\n"
        }
        if ($zone and $allow_xfer) {
            $allow_xfer =~ s{;\s*$}{};
            $allow_xfer =~ s{;\s*}{, }g;
            print "$zone allow_transfer=\"[$allow_xfer]\"\n";
        }
        $zone = "zone $1";
        $allow_update = '';
        $allow_xfer = '';
    }
    if (/^\s*allow-update\s*{\s*\w+/../}/) {
        if (/^\s*allow-update\s*{\s*(\S+)/) {
            $allow_update = $1;
            $allow_update = '' if ($allow_update eq 'key');
        } elsif (not /\bkey\b/ and /^\s*([^;]+;)/) {
            $allow_update .= ($allow_update ? ' ' : '') . $1;
        }
    }
    if (/^\s*allow-transfer\s*{\s*\S+/../}/) {
        if (/^\s*allow-transfer\s*{\s*(\S["\/\w\d\.;\s]+?);\s*}/) {
            $allow_xfer = $1;
            $allow_xfer =~ s{"}{}g;
        }
    }
}
if ($zone and $allow_update) {
    $allow_update =~ s{;\s*$}{};
    $allow_update =~ s{;\s*}{, }g;
    print "$zone allow_update=\"[$allow_update]\"\n";
}
if ($zone and $allow_xfer) {
    $allow_xfer =~ s{;\s*$}{};
    $allow_xfer =~ s{;\s*}{, }g;
    print "$zone allow_transfer=\"[$allow_xfer]\"\n";
}

Open in new window

0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35183119
That looks fine to me.
0
 
LVL 1

Author Comment

by:richsark
ID: 35183816
Sorry to be a pain

It should be like so, in addition, I played with the script to look like so...

conf zone modify foo.com set allow_transfer="[168.147.0.0/24,192.168.114.0/24]"

but I am getting

conf zone foo.com modify set allow_transfer="[168.147.0.0/24,192.168.114.0/24]"

Whay am i missing?
#!/usr/bin/perl

use strict;
use warnings;

my ($zone, $allow_update, $allow_xfer);

while (<>) {
    chomp;
    if (/^\s*zone\s*"([^"]+)"/) {
        if ($zone and $allow_update) {
            $allow_update =~ s{;\s*$}{};
            $allow_update =~ s{;\s*}{, }g;
            print "conf $zone modify set allow_update=\"[$allow_update]\"\n"
        }
        if ($zone and $allow_xfer) {
            $allow_xfer =~ s{;\s*$}{};
            $allow_xfer =~ s{;\s*}{, }g;
            print "conf $zone modify set allow_transfer=\"[$allow_xfer]\"\n";
        }
        $zone = "zone $1";
        $allow_update = '';
        $allow_xfer = '';
    }
    if (/^\s*allow-update\s*{\s*\w+/../}/) {
        if (/^\s*allow-update\s*{\s*(\S+)/) {
            $allow_update = $1;
            $allow_update = '' if ($allow_update eq 'key');
        } elsif (not /\bkey\b/ and /^\s*([^;]+;)/) {
            $allow_update .= ($allow_update ? ' ' : '') . $1;
        }
    }
    if (/^\s*allow-transfer\s*{\s*\S+/../}/) {
        if (/^\s*allow-transfer\s*{\s*(\S["\/\w\d\.;\s]+?);\s*}/) {
            $allow_xfer = $1;
            $allow_xfer =~ s{"}{}g;
        }
    }
}
if ($zone and $allow_update) {
    $allow_update =~ s{;\s*$}{};
    $allow_update =~ s{;\s*}{, }g;
    print "conf $zone modify set allow_update=\"[$allow_update]\"\n";
}
if ($zone and $allow_xfer) {
    $allow_xfer =~ s{;\s*$}{};
    $allow_xfer =~ s{;\s*}{, }g;
    print "conf $zone modify set allow_transfer=\"[$allow_xfer]\"\n";
}

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 35183839
I can open a new thread if I am out of line???
0
 
LVL 1

Author Comment

by:richsark
ID: 35183925
Sorry, made a mistake. I did not want to close this. I wanted to award points
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 35184142
If I'm understanding what you're asking, You can simply change your print statements.  This would be for the allow_update (line 14 and 43):

print "conf zone modify $zone set allow_update=\"[$allow_update]\"\n";
0
 
LVL 1

Author Closing Comment

by:richsark
ID: 35221267
Thanks for the quick response
0

Featured Post

Technology Partners: 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

Title # Comments Views Activity
AWS CLI - Instances, Volumes & Tagging 2 154
powershell code to list items in dropdown 6 113
read an xml file in perl 2 86
perl syntax 3 55
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

751 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