#!/usr/bin/perl use DBI; use DBD::mysql; my $m = '192.168.0.31'; # my IP address my $s = '192.168.0.13'; # server IP address my $u = 'username'; my $p = 'pass!word'; #$dsn = "dbi:SQL Platform:database_name:host_name:port"; my $dsn = "dbi:mysql:database_name:$s:3306"; # try to connect to mysql server my $dbh = DBI->connect($dsn,$u,$p) || die "Cannot connect to the DB: $DBI::errstr\n"; # retrieve the returned rows of data #my $sql = "SELECT `origin`, `id`, `serial`, `active` FROM `dns_soa`" my $sql = "SELECT `origin` FROM `dns_soa`" ." WHERE `active` = 'Y' AND FIND_IN_SET('$m',`also_notify`)" ." ORDER BY 1"; my $sth = $dbh->prepare($sql); $sth->execute() || die "Cannot execute the query: " . $sth->errstr; # empties the slaves file open (slave,"> /var/lib/bind/etc/bind/named.conf.slaves") || die "Cannot open named.conf.slaves for writing"; # iterating the returned rows of data while ($r = $sth->fetchrow_hashref) { $zone = substr($r->{origin},0,-1); $file = $zone; $file =~ s/\//-/g; # slashes are illegal in filenames printf slave "zone \"$zone\" {\n"; printf slave " type slave;\n"; printf slave " masters { $s; };\n"; printf slave " file \"$file.zone\";\n"; printf slave "};\n"; } close (slave); # force reload bind `/etc/init.d/bind9 force-reload`