User Tools

Site Tools


dns_add_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
dns_add_script [2009/08/18 17:55]
jt
dns_add_script [2009/08/25 00:43] (current)
jt
Line 2: Line 2:
 #​!/​usr/​bin/​perl -w #​!/​usr/​bin/​perl -w
 ##Jason Thomas ##Jason Thomas
 +##Last Modified 20090819
 +
 use strict; use strict;
 use lib '/​home/​jthomas/​lib/​perl5/​site_perl/​5.8.8/';​ use lib '/​home/​jthomas/​lib/​perl5/​site_perl/​5.8.8/';​
Line 10: Line 12:
  
  
 +##my $repository = "/​home/​jthomas/​projects/​qsp_dns_migration/​qsp.us.zone/";​
 my $repository = "/​home/​jthomas/​projects/​dns/​master/";​ my $repository = "/​home/​jthomas/​projects/​dns/​master/";​
 my $dnsData = "​data";​ my $dnsData = "​data";​
  
 +##currently designed to read from file. however if fqdn is not before fqhn, it will not be able write
 +##the entry until db.fqdn is created
  
  
Line 19: Line 24:
  
 foreach my $entry (@dnsLine){ foreach my $entry (@dnsLine){
 +
  chomp ($entry);  chomp ($entry);
 +
  my ($hostName, $ipAddress) = split('​ ', $entry);  my ($hostName, $ipAddress) = split('​ ', $entry);
-## if (  !defined($ipAddress) ) {print "​$hostName has no IP Address\n";​ exit 0;} 
  my ($domainName,​ $subDomain) = findDomainName($hostName);​  my ($domainName,​ $subDomain) = findDomainName($hostName);​
- my $dbZoneFile = checkZoneExist($domainName, $subDomain, $ipAddress);​ + checkZoneExist($domainName,​ $subDomain, $ipAddress);​
- addToZone($dbZoneFile, $subDomain, $ipAddress);​+
 } }
  
Line 47: Line 51:
  return ($hostName, undef);  return ($hostName, undef);
  }  }
- +
  else{  else{
   
Line 55: Line 59:
  
  if ( ! defined($subDomain) ){  if ( ! defined($subDomain) ){
 +
  $subDomain=$tmp[$counter];​  $subDomain=$tmp[$counter];​
   
  }  }
 +
  else{  else{
 +
  $subDomain="​$subDomain.$tmp[$counter]";​  $subDomain="​$subDomain.$tmp[$counter]";​
   
  }  }
  }  }
 +
  return ($domainName,​ $subDomain);​  return ($domainName,​ $subDomain);​
  }  }
Line 72: Line 80:
  my $dbZoneFile = "​db.$domainName";​  my $dbZoneFile = "​db.$domainName";​
  my $userName = "​jthomas";​  my $userName = "​jthomas";​
- my $soa = "​2009081801";​+ my $soa = "​2009081801 ​   ";
  
  if ( -e $repository.$dbZoneFile ){  if ( -e $repository.$dbZoneFile ){
- ## print "File Exists!"​; +  
 + ## write subdomain to file if file exists;  
 + addToZone($dbZoneFile,​ $subDomain, $ipAddress);​ 
 +
  }  }
   
- else{+ elsif ( (! defined($subDomain)) ||  $subDomain eq ""​){ 
 +
  my ($tabs) = tabLength($domainName."​."​);​  my ($tabs) = tabLength($domainName."​."​);​
  makeZone("​customArecord.tmpl",​ $dbZoneFile, ​ {soa => \$soa, userName => \$userName, domain => \"​$domainName.",​ tabs => \$tabs, CUSTOMIP => $ipAddress });  makeZone("​customArecord.tmpl",​ $dbZoneFile, ​ {soa => \$soa, userName => \$userName, domain => \"​$domainName.",​ tabs => \$tabs, CUSTOMIP => $ipAddress });
 +
  }  }
   
- return $dbZoneFile;​ 
 } }
- 
- 
  
 sub makeZone{ sub makeZone{
   
- my ($templateSource,​$dbZoneFile,​ $fillInHash) = @_;+ my ($templateSource,​ $dbZoneFile,​ $fillInHash) = @_;
  my $template = Text::​Template->​new(SOURCE => $templateSource) or die "​Couldn'​t construct template: $Text::​Template::​ERROR";​  my $template = Text::​Template->​new(SOURCE => $templateSource) or die "​Couldn'​t construct template: $Text::​Template::​ERROR";​
  my $result = $template->​fill_in(HASH => $fillInHash);​  my $result = $template->​fill_in(HASH => $fillInHash);​
 +
 +     if (! defined $result) {
 +        die "​Couldn'​t fill in template: $Text::​Template::​ERROR";​
 +    }
   
  open(DBFILE,​ ">​$repository/​$dbZoneFile"​) , or die $! ;  open(DBFILE,​ ">​$repository/​$dbZoneFile"​) , or die $! ;
Line 115: Line 129:
   
  else {  else {
 +
  my ($tabs) = tabLength($subDomain);​  my ($tabs) = tabLength($subDomain);​
  open(DBFILE,​ ">>​$repository/​$dbZoneFile"​) , or die $!;  open(DBFILE,​ ">>​$repository/​$dbZoneFile"​) , or die $!;
  print DBFILE "​$subDomain$tabs"​."​IN\tA\t$ipAddress\n";​  print DBFILE "​$subDomain$tabs"​."​IN\tA\t$ipAddress\n";​
  close (DBFILE);  close (DBFILE);
 +
  }  }
  }   }
Line 132: Line 148:
  return $tabs;  return $tabs;
 } }
 +
   
 ###########################################################################​ ###########################################################################​
Line 148: Line 165:
     exit(0);     exit(0);
 } }
- +
 </​code>​ </​code>​
dns_add_script.txt · Last modified: 2009/08/25 00:43 by jt