home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / ticscrip.zip / dns / genstatic < prev    next >
Text File  |  1992-08-31  |  1KB  |  56 lines

  1. #!/bin/sh
  2. # @(#) genstatic 1.4 92/08/31 @(#)
  3. # generate the static hosttable from database files
  4. # called from updatehosts
  5. #
  6. # files used
  7. #    hosts.local
  8. #    hosts.main
  9. #    hosts.cname
  10.  
  11. # Copyright (c) 1992 by Texas Internet Consulting
  12. # This code may be freely copied and used so long as this
  13. # copyright notice is attached.  This code may not be sold
  14. # without the express written permission of Texas Internet Consulting.
  15. # Texas Internet Consulting makes no warranty as to the correctness
  16. # nor the applicability of this code for any purpose.
  17.  
  18. # this cannot be /etc/hosts
  19. HOSTS=hosts.static
  20. SERIAL=serial
  21. PATH=.:$PATH
  22.  
  23. # put the serial number of this table as the first line
  24. serial=`cat $SERIAL`
  25. echo "# $serial" >$HOSTS
  26.  
  27. # extract host name and IP address from hosts.main
  28. readinfo ip host <hosts.main  | awk '
  29. {
  30.     # split up the domain name
  31.     n = split($2, domain, ".")
  32.     printf("%s %s %s\n", $1, $2, domain[1])
  33. }' >>$HOSTS
  34.  
  35. # build edit script for aliases
  36. readinfo host alias <hosts.cname | awk '
  37. {
  38.     # extract simple alias name from domain name
  39.     n = split($2, alias, ".")
  40.     # split up the domain name
  41.     n = split($1, domain, ".")
  42.     # build the edit command for this line
  43.     # will look like /<domain>/s/$/<alias> <alias.domain>/
  44.     edcmd = "/" domain[1]
  45.     # replace "." with "\."
  46.     for (i=2; i<=n; i++) {
  47.         edcmd = edcmd "\\." domain[i]
  48.     }
  49.     edcmd = edcmd "/s/$/ " $2 " " alias[1] "/"
  50.     print edcmd
  51. }
  52. END {
  53.     print "w"
  54.     print "q"
  55. }' | ed >/dev/null 2>&1 $HOSTS
  56.