home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / dnsparse / mkhosts < prev    next >
Encoding:
Text File  |  1996-10-25  |  1.5 KB  |  70 lines

  1. #!/usr/bin/perl
  2. #
  3. # mkhosts
  4. #
  5. # $Id: mkhosts,v 8.1 1996/10/25 04:57:11 vixie Exp $
  6. # $Source: /proj/src/isc/cvs-1/bind/contrib/dnsparse/mkhosts,v $
  7. #
  8. # Usage:
  9. #    ./mkhosts
  10. #
  11. # Front-end to create /etc/hosts files from DNS data.
  12. #
  13. # Creates a HOSTS.<domain>.<version> file for each domain listed in
  14. #  the ./domlist file.  That file should contain one domain per line, e.g.:
  15. #    cse.ogi.edu
  16. #
  17. # Also requires ./zonelist file containing filename,zonename pairs for
  18. #  each zone, one pair per line, e.g.:
  19. #    /usr/local/named/conf/zone.ogi.cse,cse.ogi.edu
  20. #
  21. # Runs ./dns2hosts for "real" work.
  22. #
  23. # Distribution of the resultant HOSTS.* files is done elsewhere,
  24. #  perhaps by a parent Makefile or calling script, etc.
  25. #
  26.  
  27. $ver = &getver;
  28.  
  29. $zone = &getzonelist;
  30.  
  31. open(DOM, 'domlist') || die "Couldn't open 'domlist': $!\n";
  32.  
  33. $| = 1;        # set STDOUT to flush
  34.  
  35. while (<DOM>) {
  36.   chop;
  37.   $fil=HOSTS.".".$_.".".$ver;
  38.   print "$fil\n";
  39.   system("./dns2hosts -d$_ $zone > $fil");
  40.   chmod(0444,$fil);
  41. }
  42.  
  43.  
  44. sub getzonelist {
  45. #
  46. # Read ./zonelist, return a list of filename,zonename pairs for dns2hosts args.
  47. # Equivalent to `cat zonelist` .
  48. #
  49.     open(ZONE, 'zonelist') || die "Couldn't open 'zonelist': $!\n";
  50.     while (<ZONE>) {
  51.         chop;
  52.         $zonelist = $zonelist." ".$_;
  53.     }
  54.     return($zonelist);
  55. }
  56.  
  57.  
  58. sub getver {
  59. #
  60. # Generate a version number string for HOSTS.* files, based on current date.
  61. # Example: Thu May 20 1993 becomes 930520 .
  62. #
  63.     ($sec,$min,$hour,$mday,$mon,$year,@rest) = localtime(time);
  64.     $mon++;     # convert to 1 == January
  65.     $ver = sprintf('%02d%02d%02d', $year, $mon, $mday);
  66.     return($ver);
  67. }
  68.  
  69.  
  70.