perl Compare zone files in directory with what is listed in named.conf


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl Compare zone files in directory with what is listed in named.conf
# 1  
Old 05-15-2013
perl Compare zone files in directory with what is listed in named.conf

I would really appreciate any assistance that I can get here.

I am fairly new to perl. I am trying to rewrite my shell scripts to perl.

Currently I have a shell script (using sed, awk, grep, etc) that gets a list of all of the zone files in a directory and then looks in named.conf for what is expected to be in there. If there is a file in the directory that isn't listed in named.conf, then it emails and lets me know that there is some stale files for me to look at.

In the past, I have used Text:Smilieiff module to do a diff. Is there any way to put these into two arrays and do a diff without that module? Looking for feedback on either using a module, or doing it without a module. There is more than one way, right?


This is sample named.conf:

Code:
###########################################
# BIND 9 name server configuration file 
###########################################

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

zone "test.com" in {
	type master;
	file "db.test.com"; 
	notify yes; 
};

zone "brian.com" in {
	type master;
	file "db.brian.com"; 
	notify yes; 
};

zone "." in {
	type hint;
	file "db.cache";
};

zone "0.0.127.in-addr.arpa" in {
	type master;
	file "db.127.0.0";
};


This is listing of zonefiles in directory:


Code:
computer:zonefiles brian$ ls -al ~/zonefiles
total 0
drwxr-xr-x   5 brian  brian  170 May 15 14:58 .
drwxr-xr-x  11 brian  brian  374 May 15 14:59 ..
-rw-r--r--   1 brian  brian    0 May 15 14:48 db.127.0.0
-rw-r--r--   1 brian  brian    0 May 15 14:48 db.brian.com
-rw-r--r--   1 brian  brian    0 May 15 14:48 db.test.com


This is the script so far:


Code:
#!/usr/bin/perl
#  Putting all of the zonefiles lised in named.conf into an array

my $srce = "named.conf.brian";
my $string1 = "db.";
open(my $FH, $srce) or die "Failed to open file $srce ($!)";
my @buf = <$FH>;
close($FH);
my @lines = grep (/$string1/, @buf); #grepping for db.
map {s/"//g; } @lines; #removing quotation marks
map {s/;//g; } @lines; #removing semicolon
#map {s/^.*file.*db.//g; } @lines; #removing file db.
map {s/^.*file //g; } @lines; #removing the word file
print @lines;
 
#  Putting listing of all of the files in /Users/brian/Documents/tmp/zonefiles directory into an array

#  Assigning variable to directory
my $directory = "/Users/brian/Documents/tmp/zonefiles/";

opendir(D, "$directory") || die "Can't opendir $directory: $!\n";
my @list = readdir(D);
closedir(D);

foreach my $f (@list) {
  print "$f\n";
}


This is the output when I run it:

Code:
computer:tmp brian$ ./brian.pl 
db.test.com 
db.brian.com 
db.cache
db.127.0.0
.
..
9
db.127.0.0
db.brian.com
db.test.com


How would I ignore things that I don't want to check? For example, ignore db.cache in named.conf. I also want to ignore "." and ".." in the zone file directory.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Want to delete the junk files from a directory which are not listed in a TEXT file

Hello Everyone, I want to delete the image files from a directory, which are not listed in a TEXT file. The directory contains large number of image files (in millions) required / not required. I want to delete the image files which are "not required". I have generated a Text file having... (3 Replies)
Discussion started by: Praveen Pandit
3 Replies

2. Shell Programming and Scripting

Cat files listed in text file and redirect to new directory with same filename

I have a directory that is restricted and I cannot just copy the files need, but I can cat them and redirect them to a new directory. The files all have the date listed in them. If I perform a long listing and grep for the date (150620) I can redirect that output to a text file. Now I need to... (5 Replies)
Discussion started by: trigger467
5 Replies

3. Shell Programming and Scripting

Copy files listed in text file to new directory

I am trying to write a script that will copy all file listed in a text file (100s of file names) to a new directory Assume script will run with main as current working directory and I know how many files/lines will be in List.txt Im trying to work up a test script using this model Contents of... (2 Replies)
Discussion started by: IAmTheGrass
2 Replies

4. Shell Programming and Scripting

Move all files not in a directory into a subdirectory named for each given file

Hi Everyone! Looking for some help with a script that will take all files in any given root folder (which are not already in a folder) and put them into separate folders with the name of each given file. Any ideas? Thank you! (1 Reply)
Discussion started by: DanTheMan
1 Replies

5. Shell Programming and Scripting

Cut the first column in listed files > PERL script

Hi All, Using this command wc -l *e* > create2.txt i'm getting the following output >>>create2.txt listed output files, my requirement is how to cut the first coloum in all the files mentioned in create2.txt in perl. 50 allignment.pl 3 create.txt 4 application.txt ... (8 Replies)
Discussion started by: adaleru
8 Replies

6. Shell Programming and Scripting

Moving files listed in a data file to a new directory using Perl

Hi, I have a data file that lists a number of files. I want to move the files named in that one to another directory. Here's what I have: #!/usr/bin/perl -w open(FILE, "<collision.txt"); my @lines=<FILE>; foreach my $lines (@lines) { system("mv $lines collisions/."); } close(FILE); ... (2 Replies)
Discussion started by: renthead720
2 Replies

7. Shell Programming and Scripting

Finding missing files that are named sequentially with Perl?

Hello I am new to Perl, in fact I am on chapter one of the book. :) However I am in need of a Perl Script faster than I can finish the book. Perhaps someone can help me with my immediate need while I read my book. I have a directory with hundreds of files that are all named like... (4 Replies)
Discussion started by: newftronics
4 Replies

8. Shell Programming and Scripting

compare db zone files in 2 directories

Hi, I am in need of a way to compare ( perhaps a shell script or Perl ) many db.X files that are located in 2 separate directories but strip out the first 11 lines from ; ; THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT IT. ; THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT IT. ; THIS... (2 Replies)
Discussion started by: richsark
2 Replies

9. Shell Programming and Scripting

seeking help with perl to read named.conf

Hello, I am seeking help with someone with perl expertise that can create me a script that will read a named.conf file and create a csv or a text file on each of the zones that the named.conf contains. An excerpt of named.conf looks like: acl "our_nets" { 127.0.0.1/32; ... (2 Replies)
Discussion started by: richsark
2 Replies

10. HP-UX

CVSWeb - Directories listed but files not listed

I am using CVSWeb on HPUnix. When i access it, all directories are listed but files are not listed. I am getting the error "NOTE: There are 51 files, but none matches the current tag. " in tomcat sevrer log i am getting the message "rlog warning: Missing revision or branch number after -r"... (0 Replies)
Discussion started by: ganesh
0 Replies
Login or Register to Ask a Question