#!/usr/bin/perl
use DBI;
use DBD::mysql;
my $username="mydns";
my $password="changepassword";
my $dsn = 'dbi:mysql:mydns:localhost:3306';
my $dbh = DBI->connect($dsn, $username, $password) or die "Can<92>t connect to the DB: $DBI::errstr\n";
  ### Retrieve the returned rows of data
  open (slave, "> /etc/dns/named.conf.local") || die "can't open named.slave for writing";
my $sql="SELECT id,origin,ns,mbox,acct FROM soa";
my $sth = $dbh->prepare($sql);
$sth->execute() or die "can't execute the query: " . $sth->errstr;
while ($hash_ref = $sth->fetchrow_hashref)
	{
	$id=$hash_ref->{id};
	$origin=$hash_ref->{origin};
	$ns=$hash_ref->{ns};
	$mbox=$hash_ref->{mbox};
	$length = length($origin);
	$zone = substr($origin, 0, $length-1);
	printf slave "zone \"$zone\" { \n";
	printf slave "type slave;\n";
	printf slave "masters { 192.168.1.49; 192.168.2.49; };\n";
	printf slave "file \"/var/dns/db.$zone\";\n";
	printf slave "};\n\n";
	}
close (slave);


