Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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::Diff 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:

########################################### # 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:

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:

#!/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 ~/zonefiles directory into a +n array # Assigning variable to directory my $directory = "~/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:

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.


In reply to Compare zone files in directory with what is listed in named.conf by brianjb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (5)
    As of 2015-07-04 05:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (57 votes), past polls