Parvinder Bhasin <[EMAIL PROTECTED]> writes: > I am writing up a script to automatically increment the serial number > of bind dns zone file , but I am running across issues doing in place > substitution with either sed or even perl for that matter. I can do > this easily in Linux but am having hard time doing so in openbsd. I > would like to search for the serial number , increment by one and then > save the file. > > Any help...highly appreciated. > > Thx. > > Here is my code snippet: > > [...]
Hello, Here is such a script I made: http://hyrule.folays.net/serial.pl <<< #!/usr/bin/perl -w use strict; use File::stat; $^I = ""; @ARGV = (); push @ARGV, glob "*.{net,org,fr,com,in-addr.arpa,local}"; push @ARGV, ("private", "public"); my @file = @ARGV; foreach (@file) { my $name = $_; my $sb = stat($name); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($sb->mtime); $year += 1900; $mon += 1; my $serial = sprintf("%d%02d%02d%02d", $year, $mon, $mday, 1); @ARGV = (); push @ARGV, $name; if ($sb->ctime == $sb->mtime) { while (<>) { if ($_ =~ m/;.*serial/i) { my $last = $_; $last =~ s/^([[:space:]]+)([[:digit:]]+)([[:space:]]*;.*serial.*)/$2/ix; chomp $last; ($serial = $last + 1) if (substr($last,0,8) eq substr($serial,0,8)); s/$last/$serial/; } print; } close STDIN; utime $sb->atime, $sb->mtime-1, $name; printf ";; SOA of $name\n"; printf "; serial: %s.\n", $serial; } else { printf ";; serial/modification time of $_ differ, skipping...\n"; } } >>> The basic idea is that it consider that if the inode time is the same that the modification time, then it will update the serial and set the modification time 1 second back of the inode time (thus removing the needs to keep a separate file to register when the file was last modified or even always updating serial of untouched files). The serial format is a string representation of the date + 2 serial digits I use it on occasionally manual changes, so the counter will overflow to the next day if you use it more than 100 times on a given file. -- folays