From 7d35c95bc523267b6776c49d3e54eb297f76023e Mon Sep 17 00:00:00 2001 From: hjp Date: Mon, 28 Apr 2008 15:57:05 +0000 Subject: [PATCH] Added dns-inc-serial to increment the serial number in a DNS zone file. --- dns/dns-inc-serial | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 dns/dns-inc-serial diff --git a/dns/dns-inc-serial b/dns/dns-inc-serial new file mode 100755 index 0000000..78d8fe9 --- /dev/null +++ b/dns/dns-inc-serial @@ -0,0 +1,23 @@ +#!/usr/bin/perl +use warnings; +use strict; + +# Idea for improvement: +# take maximum of serial from file and from all authoritative nameservers, +# then increment by one. + +for my $f (@ARGV) { + rename $f, "$f.old" || die "cannot rename $f to $f.old: $!"; + open (my $in, '<', "$f.old") or die "cannot open $f.old: $!"; + open (my $out, '>', "$f") or die "cannot open $f: $!"; + while (<$in>) { + if (/(.*\bSOA\b.*?)(\d+)( \d+ \d+ \d+ \d+)/) { + my $serial = $2; + $serial++; + print $out "$1$serial$3\n"; + } else { + print $out $_; + } + } + close($out) or die "cannot close $out"; +}