Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jul 2002 20:06:15 -0400 (EDT)
From:      Jim Weeks <jim@jwweeks.com>
To:        freebsd-isp@FreeBSD.ORG
Subject:   Re: Scripts to Manage Virtual Hosts
Message-ID:  <20020716194233.D368-100000@veager.jwweeks.com>
In-Reply-To: <Pine.BSF.4.21.0207121029090.45401-300000@thud.tbe.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Since everyone is in the sharing mood, maybe this will be helpful.  I
wrote this some time ago to add sub-domains, and have carried it around
from script to script.  Maybe not the most elegant coding, but it works.

Regards,
--
Jim

$dateCmd = '/bin/date';
chop ($dateStamp = `$dateCmd +"%Y%m%d"`);
$recfile = "/etc/namedb/XXXXXX.com";

# add new named entry
sub named {
  # Open record file for reading.
  open(NAMED,"$recfile") || die ("can't open $recfile");
    while (<NAMED>) {
      # Find and extract serial number.
      if ($_ =~ /Serial/) { $serno = $_;
        $serno =~ s/\D+//g;
        $serno =~s/(\d{4})(\d{2})(\d{2})(\d{2})/$serno/;
        $oldate = $1 . $2 . $3;
        $yr=$1; $mo=$2; $dy=$3; $tt=$4;
        # Increment serial number if already updated today.
        if ($dateStamp eq $oldate) {
          ++$tt;
        }
        else { $tt="00"; }
      # Replace serial number.
      $_ =~ s/\d+/$dateStamp$tt/;
      }
      # Construct new record.
      push (@ips,$_);
  }
  close(NAMED);

  # Write new config file.
  open(NAMED,">$recfile") || die ("can't open $recfile");
  print NAMED @ips;
  print NAMED "$user 			IN A XXX.XXX.XXX.XXX\n";
  close(NAMED); undef @ips;
}

# restart named
sub restart_named {
  open(CMD,"|/bin/kill -1 `cat /var/run/named.pid`");
  close (CMD);
}


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-isp" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020716194233.D368-100000>