Main Page Content
Dirty Shell Scripts Part 2 Dns Updates
Daniel posted his excellent quick and dirty script for adding sites to your Apache Conf
File. Here's my quick and dirty script for adding domains to your DNS config files. (Myscript does not provide the ego boost Daniel's does ;-)Since I park quite a few domains for friends, as well as provide redirection/bounce
domains for some companies I many times need to do batches of domains. With the script andtemplate below, you can either pass the script one domain name, or pass it a file that hasa list of domain names. The script will then create a named.<domainname> file foreach domain and also create an add.named.conf file that you can then manually append toyour named.conf file.For my LINUX server, named files reside in /var/named. I created a special
sub-directory called 'park' to store all my 'other' domains. I keep all my personal and mypersonal business domains in /var/named, this allows for less clutter. The script assumesthat you set up your parked domains the same. You can edit it to either not do that, oradd additional functionality to branch on demand.To use the script below, cut out the new-site.cgi
named.template
and save as a text file inthe same directory as new-site.cgi.For One Domain, To activate:
root@foobar park>./new-site.cgi
For More than one domain, create a text file with the list of new domains.
e.g. newsites.file
newsite1.com
newsite3.com
etc.
To activate:
root@foobar park>./new-site.cgi -f
Take the add.named.conf file and append it to your named.conf file. Restart named.
Hope this saves you some time and most of all have fun!!.
new-site.cgi
#!/usr/bin/perl -w#### Creates a new named file from## named.template and appends info## Does not restart named service!!#### Accepts two types of input## -f <filename>## or## <domainname>#### -f indicates read from file a## list of domain names to process #### <domainname> means just processif ($#ARGV > -1) {
if ($ARGV[0] eq "-f") { if (open (FILE, "<$ARGV[1]")) { while ($ReadLine = <FILE>) { chomp($ReadLine); &CreateNameDFile($ReadLine); &AddToNameDConfig($ReadLine); } # end while (<FILE>) close (FILE); } else { print "Could not open $ARGV[1]";
exit; } # end if (open (FILE, "<$ARGV[1]") } else { if ($ARGV[0] ne "" && $ARGV[0] ne "" ) { &CreateNameDFile($ARGV[0]); &AddToNameDConfig($ARGV[0]); } else { print "no arguments given..."; print " use -f \<filename> or<domainname>";
exit; } # end if ($ARGV[0] ne "" && $ARGV[0] ne "" } # end if ($ARGV[0] ne "-f")} else { print "no arguments given..."; print " use -f \<filename> or <domainname>";
exit;} # end if ($#ARGV >0)</small><small>sub CreateNameDFile { $varNewFileName = "named." . "$_[0]"; open (TEMPLATE, "<./named.template"); open (DUMP, ">./$varNewFileName"); while ($Line = <TEMPLATE>) { $Line =~ s/replaceme/$_[0]/g; print DUMP $Line; } # end while (<TEMPLATE>) close (DUMP); close (TEMPLATE); print "Completed new named file for $_[0] ";} # end sub CreateNameDFilesub AddToNameDConfig {
open (DUMP, ">>./add.named.conf"); print DUMP "zone \"$_[0]\" {"; print DUMP " type master;"; print DUMP " file \"park\/named." . "$_[0]" ."\";"; print DUMP "};";
close (DUMP); print "Added $_[0] info to add.named.conf file.";
} # end sub AddToNameDConfigexit;
named.template
;
example add.named.conf file
zone "foobar.org" {type master;file "park/named.foobar.org";};zone "foo.com" {
type master;file "park/named.foo.com";};