home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / n / bind / bind-4.001 / bind-4~ / bind-4.9.3-BETA9 / contrib / misc / update-soa.csh < prev    next >
Internet Message Format  |  1994-02-16  |  3KB

  1. Return-Path: bind-workers-request
  2. Received: by gw.home.vix.com id AA15120; Tue, 15 Feb 94 16:23:37 -0800
  3. Received: by gw.home.vix.com id AA15116; Tue, 15 Feb 94 16:23:32 -0800
  4. Received: by hot.ee.lbl.gov for bind-workers@vix.com (5.65/1.43r)
  5.     id AA03216; Tue, 15 Feb 94 16:23:16 -0800
  6. Message-Id: <9402160023.AA03216@hot.ee.lbl.gov>
  7. To: bind-workers@vix.com
  8. Subject: Re: Suggested HACK to allow recovery after SOA typo ...
  9. Date: Tue, 15 Feb 94 16:23:15 PST
  10. From: Craig Leres <leres@ee.lbl.gov>
  11.  
  12. People have mentioned making typos when updating the SOA serial; I
  13. wrote the appended script and we don't have this problem anymore.
  14. It does require that the file be writable (we keep our dns
  15. files in RCS) and that the serial number on a line by itself
  16. and directly follow the soa, e.g.:
  17.  
  18. @               in      soa     ns1.lbl.gov. hostmaster.ns1.lbl.gov. (
  19.                                         94021509
  20.                                         14400   ; refresh
  21.                                         1800    ; retry
  22.                                         3600000 ; expire
  23.                                         86400 ) ; minimum
  24.  
  25.  
  26.         Craig
  27. ------
  28. #!/bin/csh -f
  29. # @(#) $Header: updateserial,v 1.7 93/10/08 17:33:04 leres Exp $ (LBL)
  30. #
  31. # updateserial - Update the SOA serial in the specified files.
  32. #
  33.  
  34. set prog=$0
  35. set prog=$prog:t
  36.  
  37. # Construct a serial of the form YYMMDDHH
  38. set m="-e s/Jan/01/ -e s/Feb/02/ -e s/Mar/03/ -e s/Apr/04/"
  39. set m="$m -e s/May/05/ -e s/Jun/06/ -e s/Jul/07/ -e s/Aug/08/"
  40. set m="$m -e s/Sep/09/ -e s/Oct/10/ -e s/Nov/11/ -e s/Dec/12/"
  41.  
  42. set serial=`date | sed $m -e 's/^... \(..\) \(..\) \(..\):..:.. ... ..\(..\)/\4\1\2\3/' -e 's/ /0/g'`
  43.  
  44. # If wrong number of arguments, give usage.
  45. if ( $#argv < 1 ) then
  46.     echo "usage: $prog dns-file ..."
  47.     echo "(Current serial is $serial)"
  48.     exit 1
  49. endif
  50.  
  51. # Loop through arguments and process.
  52. while ($#argv > 0)
  53.     # Don't munge file unless writable
  54.     if (! -w $1) then
  55.     echo "Warning: $1 not writable, skipping..."
  56.     shift
  57.     continue
  58.     endif
  59.     # Extract old serial
  60.     set temp=$1.$$
  61.     mv $1 $temp
  62.     set oldserial=`head -50 $temp | sed -n -e "/[iI][nN][     ][     ]*[sS][oO][aA]/{n" -e "s/[^0-9]*\([0-9][0-9]*\).*/\1/p" -e "}"`
  63.  
  64.     # Insure new serial is at least one higher than old serial
  65.     set newserial=$serial
  66.     if ("$oldserial" != "") set newserial=`echo $oldserial $newserial | awk -e '{if ($1 >= $2) $2 = $1+1; print $2}'`
  67.  
  68.     # Munge the file
  69.     sed -e "/[iI][nN][     ][     ]*[sS][oO][aA]/{n" -e "s/[0-9][.0-9]*/$newserial/" -e "}" \
  70.     $temp > $1
  71. #    diff $1 $temp >&/dev/null
  72. #    if ( $status == 0 ) then
  73. #    echo "Warning: serial didn't change, restoring $1"
  74. #    mv -f $temp $1
  75. #    else
  76.     rm -f $temp
  77. #    endif
  78.     shift
  79. end
  80.  
  81. exit
  82.