From: Don Armstrong Date: Sun, 8 Mar 2009 00:29:01 +0000 (+0000) Subject: * add more error correcting and handle bad files more gracefully X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=d8f1b6a97ffcdce413f8130fe44d4d0cd86f8078;p=bin.git * add more error correcting and handle bad files more gracefully --- 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())) {