Index: [Article Count Order] [Thread]

Date:  Wed, 22 Oct 2008 21:41:08 +0200
From:  Michael Stauber <bq (at mark) solarspeed.net>
Subject:  [coba-e:14206] Re: Mass updating DNS
To:  coba-e (at mark) bluequartz.org
Message-Id:  <200810222141.08615.bq (at mark) solarspeed.net>
In-Reply-To:  <1224701337.17833.27.camel (at mark) columbus.webtent.org>
References:  <1224701337.17833.27.camel (at mark) columbus.webtent.org>
X-Mail-Count: 14206

Hi Robert,

> need to update all mx records for many domains

Oh, right. Didn't see that. The script mentioned before was just for IP 
address changes. 

Here is one for changing MX records on the fly:

#----------------------------------------------------------------------------------
#!/usr/bin/perl -I/usr/sausalito/perl
# $Id: dns-mass_mx_change.pl, v1.1.0.0
# Wed 22 Oct 2008 03:31:37 PM EDT Exp $
# Copyright 2006-2008 Solarspeed Ltd. All rights reserved.

use CCE;
my $cce = new CCE;

$cce->connectuds();

# Old MX Server name:
$oldmx = 'mail.olddomain.com';

# New MX Server name to use instead:
$newmx = 'mail.newdomain.com';

# Change ALL MX records to the new name,
# not just the one defined in $oldmx
# '0' = NO
# '1' = YES - change all
$changeall = '0';

&feedthemonster;
&setdirty;

$cce->bye('SUCCESS');
exit(0);

sub feedthemonster {
    if ( $changeall == '0') {
        (@oids) = $cce->find('DnsRecord', {
                    'mail_server_name' => $oldmx, 'type' => "MX"
                  });
        for $object (@oids) {
            print $object . "\n";
                ($ok) = $cce->set($object, '',{
                    'mail_server_name' => $newmx
                });
        }
    }
    else {
        (@oids) = $cce->find('DnsRecord', { 'type' => "MX" });
        for $object (@oids) {
            print $object . "\n";
                ($ok) = $cce->set($object, '',{
                    'mail_server_name' => $newmx
                });
        }
    }
}

sub setdirty {
    # Get 'System' details:
    @system_main = $cce->find('System');
    if (!defined($system_main[0])) {
        print "Sorry, no 'System' object found in CCE!\n";
        exit(1);
    }
    else {
        # Build Records:
        #($ok, $my_system_main) = $cce->get($system_main[0]);
        ($ok) = $cce->set($system_main[0], 'DNS', {
            'dirty' => time()
        });
    }
}
#----------------------------------------------------------------------------------

Please take special note of the variable $changeall.

With it you can either change the mail_server_name of a single domain to the 
new value, or you can change *all* MX records to the new value. 

PLEASE NOTE: Be really careful and consider if setting *all* MX records to the 
same mail exchanger is what you have in mind before you change the variable 
$changeall to '1'.

-- 
With best regards,

Michael Stauber