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())) {