Skip to content

Instantly share code, notes, and snippets.

@EdwardIII
Created April 6, 2011 11:32
Show Gist options
  • Save EdwardIII/905506 to your computer and use it in GitHub Desktop.
Save EdwardIII/905506 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use File::Slurp qw(read_file);
my @zone_files = glob('/var/named/*.db');
my $out_dir = '/home/datastore/newzones/'; # always include trailing slash
use Net::DNS::ZoneFile::Fast;
use Data::Dumper;
use File::Basename qw(basename);
foreach my $zone_file (@zone_files){
my $zone_text = read_file($zone_file);
my $rrs = Net::DNS::ZoneFile::Fast::parse($zone_text);
$zone_file = basename($zone_file);
open(my $fh, '>', $out_dir . $zone_file) or die "Couldn't open $out_dir$zone_file: $!";
foreach my $rr (@$rrs){
$rr->ttl(60) unless ($rr->type eq 'NS' || $rr->type eq 'SOA');
print $fh $rr->string . "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment