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:iff 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";
}
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.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)