Help with a possiable syntax issue in my script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with a possiable syntax issue in my script
# 1  
Old 04-28-2009
Help with a possiable syntax issue in my script

Hello
I have tried to my best ability to work around this script tht will reference my m-names.txt which contains the format of:
168.16.0.0/16
169.56.0.0/16
132.2.0.0/16
122.5.0.0/16

Then I call a cli named getzoneprof that will set the $subnet from each of the lines in the m-named.txt file

The output have lots of parts, but I am only interested in a particular section "
Sark DNS 4.X Options "

Sark DNS 4.X Options
Import External Updates=False
allow-notify=Use Server Value
allow-query=Any
allow-transfer=Any
allow-update=Use List
ACL Templates=
other=100.100.100.1
notify=No
zone block of named.conf=
zone block of named.conf=forwarders {};

Full output:

Zone=100.0.0.0/8
ParentAddress=
NetworkAddress=100.0.0.0
dnsServers=l S
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@
Extensions
Prefix of zone db file=
Postfix of zone db file=
BIND-8.X Options
allow-query=Any
allow-transfer=Any
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=Any
allow-transfer=Any
allow-update=Use Server Value
notify=Use Server Value
zone block of named.conf=allow-update {
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=};
Rich DNS 3.X Options
Import External Updates=False
allow-query=Any
allow-transfer=Any
allow-update=Use Server Value
check-names=Use Server Value
notify=Use Server Value
zone block of named.conf=allow-update {
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=};
Sark DNS 4.X Options
Import External Updates=True
A (Host IPV4)=False
AAAA (Host IPV6)=False
CNAME (Canonical Name)=False
PTR (Pointer)=False
SRV (Server Resource Record)=Fal
TXT (Text)=False
allow-notify=Use Server Value
allow-query=Any
allow-transfer=Use Server Value
allow-update=Use Server Value
notify=Use Server Value
zone block of named.conf=allow-update {
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=1
zone block of named.conf=10..
zone block of named.conf=169.
zone block of named.conf=};
WINDOWS 2000 DNS Options
aging=False

I need to capture what the Import External Updates= is set to, either True/False under Sark DNS 4.x

I have two issues, but they be all related. First the script does not log the results and also does not seem to find "Import External Updates=" and report on weather its True or False

Thanks for your help

#!perl -w
open(LOG, ">log-udates-.txt") or die "Could not open log: $!\n";

open( IN, "<m-names.txt") or die "Could not open m-names.txt: $!\n";

while( <IN> ){
chomp;
my $subnet = $_;

print "Checking $subnet\n";
my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $subnet -o steve`;

next unless (my ($IEU) = $dnsoptions =~ /Sark DNS 4.X Options.*?Import External Updates=(\S+)/s);
next unless $dnsoptions =~ /(True|False)/;

print LOG "$subnet\n";
print LOG "Sark DNS 4.X Options field found, "
. "Import External Updates= $dnsoptions\n";
}

close(LOG)
# 2  
Old 04-28-2009
I do not have Unix/Linux right now, but try out this modified script:

Code:
#!perl -w
open(LOG, ">log-udates.txt") or die "Could not open log: $!\n";
open( IN, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
while( <IN> ){
  chomp;
  my $subnet = $_;
  print "Checking $subnet\n";
  my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $subnet -o steve`;
  $/="";
  $dnsoptions =~ s/.*Sark DNS 4.X Options.*?Import External Updates=(\S+).*/$1/s;
  $/="\n";
  #next unless (my ($IEU) = $dnsoptions =~ /Sark DNS 4.X Options.*?Import External Updates=(\S+)/s);
  next unless $dnsoptions =~ /(True|False)/;
  print LOG "$subnet\n";
  print LOG "Sark DNS 4.X Options field found, "
  . "Import External Updates= $dnsoptions\n";
}
close(IN);
close(LOG);

Hope that helps,
tyler_durden

______________________________________________
"Only after disaster can we be resurrected."
# 3  
Old 04-28-2009
Hi I ran it, now its dumping all the info, I just want a report under Sark DNS 4.X Options field found
Import External Updates=

print LOG "$subnet\n";
print LOG "Sark DNS 4.X Options field found, "
. "Import External Updates= $dnsoptions\n";

Can you take another look
# 4  
Old 04-28-2009
Well, I've tweaked your script a little bit, but this is in ActiveState perl on windoze (which I have to put up with at work).
This might give you some idea.

Code:
C:\>
C:\>REM show the contents of m-names.txt
C:\>
C:\>type m-names.txt
168.16.0.0/16
169.56.0.0/16
132.2.0.0/16
122.5.0.0/16
C:\>
C:\>REM show the contents of the script "test_script.pl"
C:\>
C:\>type test_script.pl
#!perl -w
open(LOG, ">log-udates.txt") or die "Could not open log: $!\n";
open( IN, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
while( <IN> ){
  chomp;
  my $subnet = $_;
  print "Checking $subnet\n";
  #my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $subnet -o steve`;
  my $dnsoptions =
"Zone=100.0.0.0/8
ParentAddress=
NetworkAddress=100.0.0.0
dnsServers=l S
RefreshTime=3600
ExpirationTime=1209600
RetryPeriod=900
MinimumTTL=900
NegativeCacheTTL=900
ZoneMail=hostmaster@
Extensions
Prefix of zone db file=
Postfix of zone db file=
BIND-8.X Options
allow-query=Any
allow-transfer=Any
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=Any
allow-transfer=Any
allow-update=Use Server Value
notify=Use Server Value
zone block of named.conf=allow-update {
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=};
Rich DNS 3.X Options
Import External Updates=False
allow-query=Any
allow-transfer=Any
allow-update=Use Server Value
check-names=Use Server Value
notify=Use Server Value
zone block of named.conf=allow-update {
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=};
Sark DNS 4.X Options
Import External Updates=True
A (Host IPV4)=False
AAAA (Host IPV6)=False
CNAME (Canonical Name)=False
PTR (Pointer)=False
SRV (Server Resource Record)=Fal
TXT (Text)=False
allow-notify=Use Server Value
allow-query=Any
allow-transfer=Use Server Value
allow-update=Use Server Value
notify=Use Server Value
zone block of named.conf=allow-update {
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=
zone block of named.conf=1
zone block of named.conf=10..
zone block of named.conf=169.
zone block of named.conf=};
WINDOWS 2000 DNS Options
aging=False";
  $/="";
  $dnsoptions =~ s/.*Sark DNS 4.X Options.*?Import External Updates=(\S+).*/$1/s;
  $/="\n";
  #next unless (my ($IEU) = $dnsoptions =~ /Sark DNS 4.X Options.*?Import External Updates=(\S+)/s);
  next unless $dnsoptions =~ /(True|False)/;
  print LOG "$subnet\n";
  print LOG "Sark DNS 4.X Options field found, "
  . "Import External Updates= $dnsoptions\n";
}
close(IN);
close(LOG);
C:\>

I am explicitly setting the value of $dnsoptions to whatever you see from your "getzoneprof" script. Note that the value of $/ is changed only for that substitute command, which sets the value of $dnsoptions.

Code:
C:\>
C:\>REM run the perl script
C:\>
C:\>perl test_script.pl
Checking 168.16.0.0/16
Checking 169.56.0.0/16
Checking 132.2.0.0/16
Checking 122.5.0.0/16
C:\>
C:\>REM check the contents of the file "log-udates.txt"
C:\>
C:\>type log-udates.txt
168.16.0.0/16
Sark DNS 4.X Options field found, Import External Updates= True
169.56.0.0/16
Sark DNS 4.X Options field found, Import External Updates= True
132.2.0.0/16
Sark DNS 4.X Options field found, Import External Updates= True
122.5.0.0/16
Sark DNS 4.X Options field found, Import External Updates= True
C:\>
C:\>


Hope that helps,
tyler_durden

______________________________________________
"Only after disaster can we be resurrected."
# 5  
Old 04-28-2009
Hi, ok, so what shall I use for the perl script? did you use your original script?
# 6  
Old 04-29-2009
Quote:
Originally Posted by richsark
Hi, ok, so what shall I use for the perl script? did you use your original script?
Well, I could use my original script, but then this line:

Code:
  my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $subnet -o steve`;

would fail because I don't have the script "getzoneprof" in my system. And I don't know what it does.

So what I can do is - assume that the value of $dnsoptions is the *same* for each line of m-names.txt, and is equal to that long string you posted (starting with "Zone=100.0.0.0/8" and ending with "aging=False"). I can copy that string to a file called "getzoneprof.txt" and use the following line in place of the one above:

Code:
  my $dnsoptions = `cat getzoneprof.txt`;

So, here's the setup on my machine:

Code:
$ 
$ # remove any existing "log-udates.txt" file
$ rm log-udates.txt
$                  
$ # contents of m-names.txt
$ cat m-names.txt          
168.16.0.0/16              
169.56.0.0/16              
132.2.0.0/16               
122.5.0.0/16               
$                          
$ # contents of getzoneprof.txt
$ cat getzoneprof.txt          
Zone=100.0.0.0/8               
ParentAddress=                 
NetworkAddress=100.0.0.0       
dnsServers=l S                 
RefreshTime=3600               
ExpirationTime=1209600         
RetryPeriod=900                
MinimumTTL=900                 
NegativeCacheTTL=900           
ZoneMail=hostmaster@           
Extensions                     
Prefix of zone db file=        
Postfix of zone db file=       
BIND-8.X Options               
allow-query=Any                
allow-transfer=Any             
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=Any                
allow-transfer=Any             
allow-update=Use Server Value  
notify=Use Server Value        
zone block of named.conf=allow-update { 
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=};             
Rich DNS 3.X Options                    
Import External Updates=False           
allow-query=Any                         
allow-transfer=Any                      
allow-update=Use Server Value           
check-names=Use Server Value            
notify=Use Server Value                 
zone block of named.conf=allow-update { 
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=};             
Sark DNS 4.X Options                    
Import External Updates=True            
A (Host IPV4)=False                     
AAAA (Host IPV6)=False                  
CNAME (Canonical Name)=False            
PTR (Pointer)=False                     
SRV (Server Resource Record)=Fal        
TXT (Text)=False                        
allow-notify=Use Server Value           
allow-query=Any                         
allow-transfer=Use Server Value         
allow-update=Use Server Value           
notify=Use Server Value                 
zone block of named.conf=allow-update { 
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=               
zone block of named.conf=1              
zone block of named.conf=10..           
zone block of named.conf=169.           
zone block of named.conf=};             
WINDOWS 2000 DNS Options                
aging=False                             
$                                       
$ # contents of test_script.pl          
$ cat test_script.pl                    
#!perl -w                               
open(LOG, ">log-udates.txt") or die "Could not open log: $!\n";
open( IN, "<m-names.txt") or die "Could not open m-names.txt: $!\n";
while( <IN> ){                                                      
  chomp;                                                            
  my $subnet = $_;
  print "Checking $subnet\n";
  #my $dnsoptions = `./getzoneprof -u Xx -p Xx -a $subnet -o steve`;
  my $dnsoptions = `cat getzoneprof.txt`;
  $/="";
  $dnsoptions =~ s/.*Sark DNS 4.X Options.*?Import External Updates=(\S+).*/$1/s;
  $/="\n";
  #next unless (my ($IEU) = $dnsoptions =~ /Sark DNS 4.X Options.*?Import External Updates=(\S+)/s);
  next unless $dnsoptions =~ /(True|False)/;
  print LOG "$subnet\n";
  print LOG "Sark DNS 4.X Options field found, "
  . "Import External Updates= $dnsoptions\n";
}
close(IN);
close(LOG);
$
$ # now run the perl script
$ perl test_script.pl
Checking 168.16.0.0/16
Checking 169.56.0.0/16
Checking 132.2.0.0/16
Checking 122.5.0.0/16
$
$ # check the contents of log-udates.txt
$ cat log-udates.txt
168.16.0.0/16
Sark DNS 4.X Options field found, Import External Updates= True
169.56.0.0/16
Sark DNS 4.X Options field found, Import External Updates= True
132.2.0.0/16
Sark DNS 4.X Options field found, Import External Updates= True
122.5.0.0/16
Sark DNS 4.X Options field found, Import External Updates= True
$
$

Hope that helps,
tyler_durden

____________________________________________________
"Only after disaster can we be resurrected."
# 7  
Old 04-29-2009
Great !

All is ok now ! Good work
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dpkg Syntax Issue . . .

Greetings! I'm trying to get dpkg to just completely extract a multi-part *.deb archive set into a single folder called "output". Simple? Hmmmm.... dpkg --noforce --unpack *.deb /output/Console after ops: However, "--noforce" is taken directly from the helpfile Options listing as furnished... (8 Replies)
Discussion started by: LinQ
8 Replies

2. Shell Programming and Scripting

TCSH IF syntax issue

Hi All, I'm trying to write a simple if statement in TCSH and I honestly can't figure out what I'm doing wrong. I've played around with all sorts of permutations of syntax. if ($DESKTOP_SESSION == "kde") then replace "forceFontDPI=0" "forceFontDPI=96" --... (0 Replies)
Discussion started by: VerticalMule
0 Replies

3. Shell Programming and Scripting

Syntax Issue

Hello all. Need a bit of help... I have : previous_tmp0=`cat tmp0.txt` previous_tmp1=`cat tmp1.txt` previous_tmp2=`cat tmp2.txt` previous_tmp3=`cat tmp3.txt` previous_tmp4=`cat tmp4.txt` previous_tmp5=`cat tmp5.txt` previous_tmp6=`cat tmp6.txt` previous_tmp7=`cat tmp7.txt` Now I... (5 Replies)
Discussion started by: Junaid Subhani
5 Replies

4. Shell Programming and Scripting

syntax issue mysql in bash script

I'm running mysql in a bash script mysql <<EOF query EOF one query is like this: UPDATE $dbname.$prefix"config" SET value = $var WHERE "$prefix"config.name = 'table colname'; with variable but it's giving an error i'm not sure what to put for "$prefix"config.name the table... (3 Replies)
Discussion started by: vanessafan99
3 Replies

5. Shell Programming and Scripting

syntax issue with quotes in mysql command for a bash script

i'm trying to write a bash script that executes a mysql statement mysql -sN -e INSERT INTO "$database"."$tableprefix"users (var1, var2,var3) VALUES (123, '1','') i don't know where to put the quotes it doesnt work with this one: ` it seems i can only put double quotes around the... (0 Replies)
Discussion started by: vanessafan99
0 Replies

6. Shell Programming and Scripting

Syntax error, not understanding the issue?

Close please. Refer to following thread: Sub Menu issues (2 Replies)
Discussion started by: Banned
2 Replies

7. Shell Programming and Scripting

expr/bc syntax issue

Hi, I am facing issues in my shell script while trying to add two variables. Look at the snippet below for details: # Initially variable SAMPLE1 and SAMPLE2 are set from different sources. Have trucated decimal to avoid numeric errors in expr SAMPLE1=`/usr/bin/top -n 1 | head -3 | tail -1... (3 Replies)
Discussion started by: animesh303
3 Replies

8. Shell Programming and Scripting

Help understanding syntax error Issue

Hi i as you may already know i am creating a menu driven program. I have chosen to take the approach of implementing each interface individually, after adding another interface and attempting to run the program i am faced with the following error: ./Assigntest: line 32: syntax error near... (6 Replies)
Discussion started by: warlock129
6 Replies

9. Shell Programming and Scripting

syntax issue in ksh file

Hi all, I am struck with syntax for long time, Need to purge some lines from given file Not able to use value of $x Example of ksh script... Facing some syntax issue. Have Tried ‘with single , double ,backtick “” ` and \ escape character , doesn't seem to work. <line 1> echo $x #... (2 Replies)
Discussion started by: manav666
2 Replies

10. Programming

Calculate scores and probability -- Syntax issue

Hi, I am totally new to C programming on Sun Solaris environment. I am an active member on the UNIX forum and a good shell programmer. I am trying to achieve some calculations in C programming. I have the pseudo code written down but don't know the syntax. I am reading a couple of books on C... (4 Replies)
Discussion started by: madhunk
4 Replies
Login or Register to Ask a Question