in reply to DNS Failover

When I've done mass changes of DNS serial numbers, I've tended to use an in place replacement such as:

`perl -pi -e 's/2007\d\d\d\d\d\d/2007102901/' *.com`
and repeat it for the other zone types. The serial number in 'date format' is unique enough that it's just not found anywhere else in the zone files I manage.

Otherwise, moritz's suggestion of a template seems to fit your needs quite well.

Update: To check for an appropriate serial number, something like the code below could be useful:

#!/usr/bin/perl use warnings; use strict; # # warning - untested code. # Let's find the largest serial number of the lot. # my $patt = qr{200\d{7}}; my $dns_zones = '/etc/named/primary/'; # chdir $dns_zones or die "Cannot enter zone file directory.\n"; my @zones = split /\n/, `ls -1`; my $curr_time = get_serial_number(); for my $z (@zones) { open (ZONE, "<", $z) or die("Cannot open zone file $z.\n"); while(<ZONE>) { # # I habitually follow the serial # with a space, a semicolon, a space # and the word 'serial' # if ( /($patt)\s+\;\s+serial/ ) { my $serial = $1; $curr_time = ++$serial if ( $serial > $curr_time ); last; } } close(ZONE); } print "Final time = $curr_time\n"; # # replace in place here. # sub get_serial_number { my @time = localtime(); my $day = substr("0" . $time[3], -2 ); my $month = $time[4] + 1; my $year = 1900 + $time[5]; return $year . $month . $day . "01"; }

Replies are listed 'Best First'.
Re^2: DNS Failover
by bjensen34 (Initiate) on Oct 30, 2007 at 20:05 UTC
    Thanks! This is helpful as well. Kind of under the gun on this one short term so going to have to do it the dirty way for now and come back and clean it up perhaps using templates later.

    You mentioned using perl -pi -e to do this mass update yesterday and I tried from cmd line and it works great, however when I try to put it in my script it does nothing.

    Here is what I am trying to do:

    # USAGE $0 {failover|failback|status} $1 {serial}
    $VARIABLE = $ARGV[0];
    $Serial = $ARGV1;
    `perl -pi -e 's/2007\d\d\d\d\d\d/$Serial/' $ROOT_DIR/*`;

    So I pass in the serial as an arg to the script and then pass it down to the perl -pi command. What am I missing here? $ROOT_DIR is defined as well pointing to /var/named/zone.

    Sure it is something obvious and silly but any help you can provide would be greatly appreciated.

    Thank you -

    Brad Jensen