Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!sdd.hp.com!uakari.primate.wisc.edu!pikes!slate!bware From: bware@slate.mines.colorado.edu (Bob Ware 209 Green C 2733987) Newsgroups: comp.protocols.tcp-ip.domains Subject: Re: How to create /etc/hosts from zone Keywords: hosts Message-ID: <1990Nov20.221652.6680@slate.mines.colorado.edu> Date: 20 Nov 90 22:16:52 GMT References: <652@janus.Quotron.com> <19523@oolong.la.locus.com> Organization: Colorado School of Mines Lines: 142 In article <19523@oolong.la.locus.com> lee@locus.com (Lee Slaughter) writes: >In article <652@janus.Quotron.com> todd@janus.Quotron.com (Todd Booth) writes: >>Could someone point me to a program that creates an /etc/hosts >>file (with CNAMEs) from domain files. >> Here is a script I use. It is not perfect, but it works here. Also included is a script I use to create a named.rev file. Bob Ware, Colorado School of Mines, Golden, Co 80401, USA (303) 273-3987 bware@mines.colorado.edu bware@mines.bitnet ...........................cut here................................... #! /bin/csh # @(#) CSM SCCS /mines/systems/bware/named/ccncsm/SCCS/s.Mkhosts.sh 1.5 90/01/02 10:58:41 # Extracts lines from named.hosts or /etc/namedb/named.hosts that # include the #rev# string and converts them to /etc/hosts format # # To update the named.rev file: # 1. execute this program and pipe it thru ' sort -n' # 2. 'get -e SCCS/s.hosts' # 3. Replace the last part of the hosts file with the output from #1 # 4. delta the hosts file # 6. execute update.sh set HEAD = hosts.head set HOSTS = named.hosts if (! -r $HOSTS ) then set HOSTS = "/etc/namedb/$HOSTS" endif # send keyword line, etc get SCCS/s.$HEAD >& /dev/null echo -n "# %" echo -n "Z% CSM SCCS %" echo -n "P% %" echo -n "I% %" echo -n "E% %" echo "U%" echo "# This file created with script" echo "# /mines/systems/bware/named/ccncsm/SCCS/s.Mkhosts.sh" echo -n "# on host " hostname cat $HEAD echo "# The following are local hosts from the named.hosts file" set a = `fgrep '#rev#' $HOSTS | grep 'IN[ ]*A' | sed 's/;.*$//' | sed 's/^.*IN[ ]*A//' | sed 's/[^0-9.]*//' ` set n = `fgrep '#rev#' $HOSTS | grep 'IN[ ]*A' | sed 's/[ ].*$//'` if($#a != $#n) then echo "ERROR $#a != $#n" exit endif while ($#a > 0) echo -n "$a[1]" echo -n " " # 1 tab echo -n "$n[1]" echo -n " " echo -n "$n[1]" echo ".Mines.Colorado.EDU" shift a shift n end .........................cut here............................ #! /bin/csh # @(#) CSM SCCS /mines/systems/sys/named/SCCS/s.Mkrev.sh 1.9 90/07/16 09:50:25 # Extracts lines from named.hosts or /etc/namedb/named.hosts that # include the #rev# string and converts them to named.rev format. # Lines that contain #noadv# are included in the output as a comment. # # To update the named.rev file: # 1. execute Mktop.sh (this also creates a new hosts file) # 3. Replace the last part of the named.rev file with the output from #1 # 4. Increment the serial (probably should be kept in sync with named.hosts) # 5. delta SCCS # 6. execute update.sh and named.restart, to make the changes effective set DOMAIN = "Mines.Colorado.EDU." set HOSTS = named.hosts # decide which named.hosts file to use if (! -r $HOSTS ) then set HOSTS = "/etc/namedb/$HOSTS" endif #get the address and name portions of the lines containing #rev# set a = `fgrep '#rev#' $HOSTS | grep 'IN[ ]*A' | sed 's/[^0-9]*$//' | sed 's/^[^ ]*[^0-9]*[0-9]*\.[0-9]*\.//' ` set n = `fgrep '#rev#' $HOSTS | grep 'IN[ ]*A' | sed 's/[ ].*$//'` # if number of addresses != number of names, then error if($#a != $#n) then echo "ERROR $#a != $#n" exit endif # now we are ready to create the output while ($#a > 0) set x = `echo $a[1] | sed 's/\./ /'` echo -n "$x[2] $x[1]" echo -n " " # 2 tabs echo -n IN echo -n " " # 1 tab echo -n PTR echo -n " " # 1 tab echo -n "$n[1]" echo ".$DOMAIN" shift a shift n end # do it again for lines containing #noadv# set a = `fgrep '#noadv#' $HOSTS | grep 'IN[ ]*A' | sed 's/[^0-9]*$//' | sed 's/^[^ ]*[^0-9]*[0-9]*\.[0-9]*\.//' ` set n = `fgrep '#noadv#' $HOSTS | grep 'IN[ ]*A' | sed 's/[ ].*$//'` if($#a != $#n) then echo "ERROR $#a != $#n" exit endif while ($#a > 0) set x = `echo $a[1] | sed 's/\./ /'` echo -n "$x[2] $x[1]" echo -n " " # 2 tabs echo -n IN echo -n " " # 1 tab echo -n PTR echo -n " " # 1 tab echo -n "$n[1]" echo ".$DOMAIN #noadv#" shift a shift n end -- Bob Ware, Colorado School of Mines, Golden, Co 80401, USA (303) 273-3987 bware@mines.colorado.edu bware@mines.bitnet isis!csm9a!bware