#!/usr/bin/perl ###### # bind-serial-update: looks for a 10 digit string in a bind config, # set the date to today and increment the counter part # Author: Jimmy Scott # Nick: Sick` # Mail: jimmy *at* inet-solutions.be # Address: Jimmy Scott # Goordijk 66 # 2930 BRASSCHAAT # BELGIUM # source: http://pub.devbox.be ### # # Copyright (C) 2003 Jimmy Scott # # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. The names of the authors may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF # THE POSSIBILITY OF SUCH DAMAGE. # ###### if ( (! defined $ARGV[0]) || ((! defined $ARGV[1]) && ($ARGV[0] eq "-f")) ) { print "$0 [-f] \n"; exit 1; } if ($ARGV[0] eq "-f") { $file=$ARGV[1]; $forced=1; } else { $file=$ARGV[0]; } die "file does not exist\n" if (! -f $file); open FH, "$file" || die "could not open file $file: $!\n"; while () { push @content,"$_"; } close FH; FIND: foreach $record (@content) { if ( $record =~ /\D(\d{4})(\d{2})(\d{2})(\d{2})\D/ ) { $year=$1; $month=$2; $day=$3; $count=$4; $found=1; $old="$year$month$day$count"; print "$old -> "; ($s,$m,$h,$md,$m,$y,$wd,$yd,$isdst) = localtime; $y += 1900; $m += 1; $c=$count+1; if ($m < 10) { $m = "0$m" } if ($md < 10) { $md = "0$md" } if ($c < 10) { $c = "0$c" } if ($c > 99) { $c = "00" } $new="$y$m$md$c"; print "$new\n"; if ((length $old) != (length $new)) { die "error in length, update of $file aborted\n"; } $record =~ s/$old/$new/; last FIND; } } die "no serial found\n" unless $found; if (! $forced) { print "press ENTER to commit, ctrl+c to cancel. "; $do = ; } open WH, ">$file" || die "could not open file $file for writing: $!\n"; foreach $record (@content) { print WH $record; } close WH;