Solved

Condition needs fixed in my script

Posted on 2009-03-30
14
185 Views
Last Modified: 2012-05-06
Hello,
I am still in a learning phase with perl and been using things I have learned from this forum to help me. But my requirments are comming  to fast for me to catch up.

I have a series of CLI's that I need to run that do different things.

The first part getdnsvrlst.exe -u xXx -p Xxx -o orig produces all the servers in a format like so, notice some have names with out the comma,

iol2su16.lab.one.net
ure13nse01.svr.one.net,169.81.48.53
ikl3nse02.svr.one.net,169.81.54.53
gtysdie.lab2.one.net
ftredns.svr.one.net,10.164.1.53

I need to only focus on the the first part before the comma if there is a comma from the list above.

so:
iol2su16.lab.one.net
ure13nse01.svr.one.net
ikl3nse02.svr.one.net
gtysdie.lab2.one.net
ftredns.svr.one.net

Then I capture this output.

The next part I run getzonext.exe which will reference the capture from above and hopefully grab the requirements from the first part (above)

The contents from getzonext.exe looks like this,

ServerName=dns2.svr.sark.net
ParameterName=Corporate Extension
options {
        forwarders {
                   115.110.102.150;   // RDM
                   195.180.150.196;   // SDC2          
        };
        forward only;
        minimal-responses yes;
        allow-transfer { "GIINLL"; };
        allow-query { any; };
        notify no;
        version "";
                recursive-clients 2000;
                edns-udp-size 512;
};

include "db.INCLUDE.logging";
include "db.INCLUDE.forwarders-core";

I only want to know what
allow-transfer indidates, it could be anything, see one example:

allow-transfer { "GIINLL"; };

So my final-results-EXT.txt should read:
print OUT "$DNS_Server\nUnder corp extention field found allow-update is set to = $option\n\n";
or

The DNS_Server named iol2su16.lab.one.net under corp extention field found allow-update= GIINLL

Can someone modify my script to do this?
Please ignore
if($option =~ /Any|none|Use Server Value|Use List|localhost|localnets/) {
because the options can be anyting words, numbers etc... I was using a script that an expert helped me with and I tried to play with it. But it aint doining what I asked it to.

Thanks


#!perl -w
use strict;
 
print my @revlist = `getdnsvrlst.exe -u xXx -p Xxx -o orig`;
#my @extlist=
 
open OUT, ">final-results-EXT.txt" or die;
 
foreach(@revlist) {
 if(/(.*?),/) {
 
      my $DNS_Server = $1;
      print "Checking $DNS_Server\n";
print      my $dnsoptions = `getzonext.exe -u Xxx -p xXx -D $DNS_Server`;
 
      if($dnsoptions =~ /options\.x allow-transfer=(.*?)$/ism) {
        # print "$DNS_Server: allow-update=$2\n";
        my $option = $2;
        if($option =~ /Any|none|Use Server Value|Use List|localhost|localnets/) {
            print "$option matched criteria\n\n";
            print OUT "$DNS_Server\nUnder corp extention field found allow-update is = $option\n\n";
        }
      }
      else {
        # print nothing
      }
   }
} 
 
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
  • 9
  • 5
14 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 24023158
Will the allow-transfer info always be on one line?  Do you want everything after it between the { and }, or between the "?

#!perl -w
use strict;
 
my @revlist = `getdnsvrlst.exe -u xXx -p Xxx -o orig`;
 
open(my $out, ">final-results-EXT.txt") or die "Could not open output file: $!\n";
 
foreach(@revlist) {
    next unless /(.*?),/;
    my $DNS_Server = $1;
    print "Checking $DNS_Server\n";
    
    my $dnsoptions = `getzonext.exe -u Xxx -p xXx -D $DNS_Server`;
    er { "GIINLL"; };
    next unless $dnsoptions =~ /allow-transfer\s*=\s*\{\s*"(.*?)";/im;
    my $option = $2;
    print $out "$DNS_Server Under corp extention field found allow-update is = $option\n\n";
} 
 
close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24023504
Hi Adam, The allow-transfer part may not yeild the words GIINLL. it could be any variable from words to IP addresses. I just gave one example of many variables.
The allow transfer may be on many lines, but I have not determind that. Can we add a something as an option in the event I need to use it? or shall we wait.
Thanks
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24023574
If you know what it will look like, post an example here, and we can help.  If you don't know now, leave the script as is, then update later if necessary.  What I posted will get everything between the double-quotes.


I just noticed that line 14 in what I posted should not be there - just remove it.
0
Industry Leaders: 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 1

Author Comment

by:richsark
ID: 24023623
Ok, I ran it, I got an error:
Can't locate object method "er" via package "GIINLL" (perhaps you forgot to load "GIINLL"?) at E:\rich\cli\11.pl line 14.
0
 
LVL 1

Author Comment

by:richsark
ID: 24023630
Opps. we crossed posting, will remove line 14
0
 
LVL 1

Author Comment

by:richsark
ID: 24023681
Adam, I think dont put whats in the double quotes because I found an instance of
allow-transfer { none; };
So perhaps what ever is in the { } is better
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24023827

next unless $dnsoptions =~ /allow-transfer\s*=\s*\{\s*(.*?)\s*\}/im;

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24024161
Hi Adam, nothing is being written to my file "final-results-EXT.txt"
ServerName=rich1nees01.svr.us.sark.net
ParameterName=Corporate Extension
options {
        version "";
        notify no;
        allow-transfer { none; };
        minimal-responses yes;
        forwarders {
                   145.180.254.53;  // test
                   195.180.174.53;  // qtest RAC
                   155.182.238.53;  // qtest CRC1
        };
        forward only;
};
 
0
 
LVL 39

Expert Comment

by:Adam314
ID: 24024268
It was looking for "allow-transfer ="... there shouldn't be an equal sign.  
next unless $dnsoptions =~ /allow-transfer\s*\{\s*(.*?)\s*\}/im;

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24024368
Ok,
Getting close: got an error;
Use of uninitialized value in concatenation (.) or string at E:\rich\cli\11.pl line 16.
I put the corrections below:

#!perl -w
use strict;
 
my @revlist = `getdnsvrlst.exe -u xXx -p Xxx -o orig`;
 
open(my $out, ">final-results-EXT1.txt") or die "Could not open output file: $!\n";
 
foreach(@revlist) {
    next unless /(.*?),/;
    my $DNS_Server = $1;
    print "Checking $DNS_Server\n";
    
     my $dnsoptions = `getzonext.exe -u Xxx -p xXx -D $DNS_Server`;
 
     next unless $dnsoptions =~ /allow-transfer\s*\{\s*(.*?)\s*\}/im;
    my $option = $2;
   print $out "$DNS_Server Under corp extention field found allow-update is = $option\n\n";
} 
 
close($out);

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24024710
I fixed it ( beleive it or not) I corrected update is = $dnsoptions\n\n";
I am getting a whole buch of output, cant we just foucus on what I need Servername and allow-transfer=

#!perl -w
use strict;
 
my @revlist = `getdnsvrlst.exe -u xXx -p Xxx -o orig`;
 
open(my $out, ">final-results-EXT1.txt") or die "Could not open output file: $!\n";
 
foreach(@revlist) {
    next unless /(.*?),/;
    my $DNS_Server = $1;
    print "Checking $DNS_Server\n";
    
     my $dnsoptions = `getzonext.exe -u Xxx -p xXx -D $DNS_Server`;
 
     next unless $dnsoptions =~ /allow-transfer\s*\{\s*(.*?)\s*\}/im;
    my $option = $2;
   print $out "$DNS_Server Under corp extention field found allow-update is = $dnsoptions\n\n";
} 
 
close($out);

Open in new window

0
 
LVL 39

Accepted Solution

by:
Adam314 earned 500 total points
ID: 24025430
Lines 16 - 17 need to be updated
...
my $option = $1;
print $out "$DNS_Server Under corp extention field found allow-update is = $option\n\n";
...

Open in new window

0
 
LVL 1

Author Comment

by:richsark
ID: 24027481
Ok, will try now.
0
 
LVL 1

Author Closing Comment

by:richsark
ID: 31564535
As always a Genius.... a simple Genius..
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl Versus AWK? 7 96
Convert Variable to Array 4 24
Open new WPF windows - powershell 4 35
Bash script to include windows servers 13 39
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…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
The viewer will learn how to count occurrences of each item in an array.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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