cant get perl to pull information right


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cant get perl to pull information right
# 1  
Old 04-05-2009
cant get perl to pull information right

Hello,
I cant get the perl script to pull the information from

Sark DNS 4.X Options
ACL Templates=
and other=

Can someone look at the script to see why and fix it please.

FYI..Under Sark DNS 4.x ACL Templates= and other= has an indent/tab, not sure if thats the reason my the script does not work??

I spent 3 days on it. I only need it from Sark DNS 4.X Options, If it appears anywhere else, I dont care. just in Sark DNS 4.X Options


(output from final-results.txt)
2.0.0.0/8
Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=*none* and other=*none*

When I manually run it, it clearly shows its under "Sark DNS 4.x:

Code:
Zone=2.0.0.0/8
ParentAddress=
NetworkAddress=2.0.0.0
dnsServers=S230.svr.sark.net P 0,srsdns1.svr.sark.net S 0,txrtp1dns.svr.sark.net S 0,txtp2dns.svr.sark.net S 0,srsdnh2.svr.sark.net S 0,es
ne1.svr.sark.net S 0,azrp1dns.svr.sark.net S 0,artp2dns.svr.sark.net S 0,rtp1dns.svr.sark.net S 0,ohrtp2dns.svr.sark.net S 0,inrtp1dns.svr.
nkone.net S 0,irtp2dns.svr.sark.net S 0,ilrtp2dns.svr.sark.net S 0,ilrtp1dns.svr.sark.net S 0,esfdns2.svr.sark.net S 0,mirtpdns.svr.sark.net
0,mirp2dns.svr.sark.net S 0,witp1dns.svr.sark.net S 0,wirtpdns.svr.sark.net S 0,lartp1dns.svr.sark.net S 0,uxns3.cmg.sark.net S 0
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@sark.net
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
BIND-9.X Options
        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=
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        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 List
                ACL Templates=DMYBP;JTESF
                other=3.3.3.3
        notify=Use Server Value
        zone block of named.conf=
WINDOWS 2000 DNS Options
        aging=False
        allow-transfer=Use List
                List=
        allow-update=No
        no-refresh-interval=0
        notify=Use List
                List=
        refresh-interval=0
        zone-options=

Here is the below code;

Code:
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]*)/sm;
        my $Other=$1 if $dnsoptions =~ /Sark DNS 4.X.*?allow-update.*?other\s*=\s*([^\r\n]*)/sm;
        $ACLTemplate='*none*' unless $ACLTemplate;
        $Other='*none*' unless $Other;
        
        next unless $AllowUpdate =~ /(Any|None|Use Server Value|Use List|localhost|ACL 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);


Last edited by richsark; 04-05-2009 at 07:43 AM.. Reason: added code tags
# 2  
Old 04-05-2009
Untested.....

Code:
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`;
   my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ('*none*', '*none*', '*none*', '*none*');
   my $flag = 0;
   my @dnsoptions = split(/\r?\n/,$dnsoptions);
   foreach my $line (@dnsoptions){
      last if $flag == 2;
      if ($flag == 1) {
         if ($line =~ /^\s*allow-update=([^\r\n]+)/) {
            $AllowUpdate = $1;
         }
         elsif ($line =~ /^\s*ACL Templates=([^\r\n]+)/) {
            $ACLTemplate = $1;
         }
         elsif ($line =~ /^\s*other=([^\r\n]+)/) {
            $Other = $1;
         }
         elsif ($line =~ /^[A-Z]/) {
            $flag = 2;
         }
      }
      elsif ($line =~ /^Sark DNS 4.X ([^\r\n]+)/) {
         $Option = $1;
         $flag = 1;
      }
   }
   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";
}

Ask questions if necessary
# 3  
Old 04-05-2009
HI, Still no luck, this is the result's.

2.0.0.0/8
Sark DNS 4.X Options field found, allow-update is set to *none* with the values Template Name=*none* and other=*none*

Still missing the values under Sark DNS 4.x

allow-update=
ACL Templates=
other=


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 List
ACL Templates=DMYBP;JTESF
other=3.3.3.3
notify=Use Server Value
zone block of named.conf=
# 4  
Old 04-05-2009
FYI..Also, allow-update= can have one of many variables as my previous code, Need that incorporated.

Any|None|Use Server Value|Use List|localhost|ACL Template|other|localnets

I ask this, because I did not see it in your code.

Thanks
# 5  
Old 04-05-2009
any help is appericated.
# 6  
Old 04-06-2009
HI, I hate to nag, but I find it interesting that there is no comments on this.

Please let me know what more you guys need to get this resolved.

Thanks
# 7  
Old 04-06-2009
Is the data you posted the output stored in $dnsoptions from this line of your code?

Code:
my $dnsoptions = `./getzoneprof.exe -u xx -p xx -a $network -o Orig`;

If so, the code I posted works for me. I can't test your entire script, namely this part of it:

Code:
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";

I used the data you posted as dummy data stored in $dnsoptions, like so:

Code:
   my $dnsoptions = do {local $/; <DATA>};
   my ($Option, $AllowUpdate, $ACLTemplate, $Other) = ('*none*', '*none*', '*none*', '*none*');
   my $flag = 0;
   my @dnsoptions = split(/\r?\n/,$dnsoptions);
   foreach my $line (@dnsoptions){
      last if $flag == 2;
      if ($flag == 1) {
         if ($line =~ /^\s*allow-update=([^\r\n]+)/) {
            $AllowUpdate = $1;
         }
         elsif ($line =~ /^\s*ACL Templates=([^\r\n]+)/) {
            $ACLTemplate = $1;
         }
         elsif ($line =~ /^\s*other=([^\r\n]+)/) {
            $Other = $1;
         }
         elsif ($line =~ /^[A-Z]/) {
            $flag = 2;
         }
      }
      elsif ($line =~ /^Sark DNS 4.X ([^\r\n]+)/) {
         $Option = $1;
         $flag = 1;
      }
   }
   print "$network\n";
   print "Under Sark DNS 4.X Options field found, ",
         "allow-update is set to $AllowUpdate with the values Template Name=$ACLTemplate ",
         "and other=$Other\n";

__DATA__
Zone=2.0.0.0/8
ParentAddress=
NetworkAddress=2.0.0.0
dnsServers=S230.svr.sark.net P 0,srsdns1.svr.sark.net S 0,txrtp1dns.svr.sark.net S 0,txtp2dns.svr.sark.net S 0,srsdnh2.svr.sark.net S 0,es
ne1.svr.sark.net S 0,azrp1dns.svr.sark.net S 0,artp2dns.svr.sark.net S 0,rtp1dns.svr.sark.net S 0,ohrtp2dns.svr.sark.net S 0,inrtp1dns.svr.
nkone.net S 0,irtp2dns.svr.sark.net S 0,ilrtp2dns.svr.sark.net S 0,ilrtp1dns.svr.sark.net S 0,esfdns2.svr.sark.net S 0,mirtpdns.svr.sark.net
0,mirp2dns.svr.sark.net S 0,witp1dns.svr.sark.net S 0,wirtpdns.svr.sark.net S 0,lartp1dns.svr.sark.net S 0,uxns3.cmg.sark.net S 0
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@sark.net
Extensions
        Prefix of zone db file=
        Postfix of zone db file=
BIND-8.X Options
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        zone block of named.conf=
BIND-9.X Options
        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=
Rich DNS 3.X Options
        Import External Updates=False
        allow-query=Use Server Value
        allow-transfer=Use Server Value
        allow-update=Use Server Value
        check-names=Use Server Value
        notify=Use Server Value
        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 List
                ACL Templates=DMYBP;JTESF
                other=3.3.3.3
        notify=Use Server Value
        zone block of named.conf=
WINDOWS 2000 DNS Options
        aging=False
        allow-transfer=Use List
                List=
        allow-update=No
        no-refresh-interval=0
        notify=Use List
                List=
        refresh-interval=0
        zone-options=

the output is:


Under Sark DNS 4.X Options field found, allow-update is set to Use List with the values Template Name=DMYBP;JTESF and other=3.3.3.3
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to extract information from a file line by line

In the below perl code I am using tags within each line to extract certain information. The tags that are used are: STB >0.8 is STRAND BIAS otherwise GOOD FDP is the second number GO towards the end of the line is read into an array and the value returned is outputed, in the first line that... (1 Reply)
Discussion started by: cmccabe
1 Replies

2. Shell Programming and Scripting

Pull out information from output logs

My scenario is as follows. 1. I have a reference file with the IP addresses and names $ cat ref.list 10.11.xxx.xxx AA 10.12.xxx.xxx BB 10.13.xxx.xxx CC 10.14.xxx.xxx DD 2. A script runs and gets me one of the IP addresses and puts it in a separate file, for e.g... (2 Replies)
Discussion started by: Nagesh_1985
2 Replies

3. Shell Programming and Scripting

[Solved] How can I pull specific information from PS?

I need to grab information from the output of the ps command. For each line of ps output that contains _progres -b I need to get the word that follows -p. The "-p" can be anywhere after "_progres -b". Using grep to select the correct lines is no problem (e.g. ps -ef|grep "_progres \-b|grep -v... (3 Replies)
Discussion started by: Papa Lee
3 Replies

4. Programming

Adding information to c file using perl

Hi, I have c file which contains more number of tests. two or more tests in one c file. I have the XMl data regarding tests. i need to add this xml data to c file at before the test. I know which file having which test and i created hash table for that. so the problem is i have to add information... (13 Replies)
Discussion started by: veerubiji
13 Replies

5. Shell Programming and Scripting

Parsing information in perl

So i'm trying to write a perl script that logins into a network switch via ssh: #sh ip traffic IP statistics: Rcvd: 1460119147 total, 563943377 local destination 0 format errors, 0 checksum errors, 48401998 bad hop count 0 unknown protocol, 8379279 not a gateway ... (2 Replies)
Discussion started by: streetfighter2
2 Replies

6. Shell Programming and Scripting

perl script to print file information - newbie

Hi I have a perl script that prints all the video and audio file information(playing duration). It works fine in one of my friends linux laptop. But it doesn't work in my both windows and linux. My friend told me I have to do install some module ( ppm instal ...... ) but I have no... (1 Reply)
Discussion started by: srijith
1 Replies

7. Shell Programming and Scripting

Print file information using ffmpeg in perl

I am trying to print file information using ffmpeg tool in perl Here is my code use strict; use warnings; use IPC::Open3; # example my $filename = $ARGV; my %videoInfo = videoInfo($filename); print "duration: " . $videoInfo{'duration'} . "\n"; print "durationsecs: " .... (0 Replies)
Discussion started by: srijith
0 Replies

8. Shell Programming and Scripting

Please do help: Perl Script to pull out rows from a CSV file

I have CSV file that contains data in the format as shown below: ABC, 67, 56, 67, 78, 89, 76, 55 PDR, 85, 83, 83, 72, 82, 89, 83 MPG, 86, 53, 54, 65, 23, 54, 75 .. .. .. .. I want to create a script that will pull out the rows from the above sheet and paste it into another CSV file.... (12 Replies)
Discussion started by: pankajusc
12 Replies

9. Shell Programming and Scripting

Perl: adding columns in CSV file with information in each

Hi Wise UNIX Crew, I want to add 3 different columns to the file in which: 1. The first new column pulls in today's date and time 2. Second column one has a '0' 3. Third column has the word 'ANY' going down the column If my file content is as follows: "7","a","abc",123"... (1 Reply)
Discussion started by: dolo21taf
1 Replies
Login or Register to Ask a Question