Author Topic: Import many DNS A records into Zentyal's DNS server zone via script  (Read 1728 times)

hiv

  • Zen Apprentice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
I want to import many DNS A and PTR records into Zentyal's DNS server zone via script. I see that there is perl module EBox::DNS. Can i use it for my issue? And i can't find any documentation for this perl module.

hiv

  • Zen Apprentice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Import many DNS A records into Zentyal's DNS server zone via script
« Reply #1 on: November 21, 2016, 11:55:00 am »
OK. I found solution and wrote perl script.

Code: [Select]
#!/usr/bin/perl

use EBox::DNS;
use utf8;
use open ':std', ':encoding(UTF-8)';

EBox::init();
my $dns=EBox::DNS->_create;
my $domain='my.corporate.domain.com';
open(DF,"</home/administrator/hosts.txt") || die "Can't open pas-hosts: $!";
while(my $line = <DF>) {
  chomp($line);
  my ($ip, $hostname, @aliases) = split(/[\t\s]+/, $line);

  my $host = {
      name => $hostname,
      ipAddresses => [ $ip ],
      aliases => [ @aliases ],
      readonly => 0
  };

   eval { $dns->addHost($domain, $host); };
  $error = $@;
  if ($error =~ /^$/) { print "Host $hostname added successfully.\n"; }
  else { print "Error: " . $error . "\n"; };
}
close(DF);

There are some modernisations in script witch was published at https://forum.zentyal.org/index.php/topic,22580.msg86828.html#msg86828
« Last Edit: November 21, 2016, 11:57:49 am by hiv »