X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=update_dns_serial;h=9a23f89496d95a439809c0d50299f5230d2de50f;hb=7072dd6217d2a600f729188624f228b5700bd836;hp=9481402b4a2db7c00fd17ec850a932aa89b75e7d;hpb=da54d2b0713bdd85a47d2e3ed2bc925b0ad681e8;p=bin.git diff --git a/update_dns_serial b/update_dns_serial index 9481402..9a23f89 100755 --- a/update_dns_serial +++ b/update_dns_serial @@ -7,12 +7,17 @@ use IO::File; use POSIX qw(strftime); for my $file (@ARGV) { - my $fh = IO::File->new($file,'r'); - my $fh_new = IO::File->new($file.".new",'w'); + my $fh = IO::File->new($file,'r') or die "Unable to open $file for reading: $!"; + my $fh_new = IO::File->new($file.".new",'w') or die "Unable to open ${file}.new for writing: $!"; local $/; my $fh_contents = <$fh>; # rip out old serial my ($old_serial) = $fh_contents =~ /IN\s+SOA\s+\S+\s+\S+\s*(?:\s*\;.+\n)*\((?:\s*\;.+\n)*\s*(\d+)/; + if (not defined $old_serial) { + print STDERR "problem dealing with $file\n"; + unlink("${file}.new") or die "Unable to unlink ${file}.new: $!"; + next; + } my ($ymd,$iter) = $old_serial =~ /(\d{4}\d{2}\d{2})(\d{1,2})/; my $new_serial = strftime("%Y%m%d",gmtime())."01"; if ($ymd eq strftime("%Y%m%d",gmtime())) {