Listing 2: nsupdate shell

  #!/bin/sh
  #
  #
  # this script builds the file master.out (the SOA for sinag.com)
  # (actully the only real change that ever takes place is the
  #  updated serial number -- it's based on the date)
  #
  #                                            mrg 7/15/91
  #
  config=./ns.config

  seqfile=`cat $config | grep "^seq" | cut -d= -f2`
  output=`cat $config | grep "^output" | cut -d= -f2`

  origin=`cat $config | grep "^origin" | cut -d= -f2`
  authns=`cat $config | grep "^authns" | cut -d= -f2`
  authaddr=`cat $config | grep "^authaddr" | cut -d= -f2`
  contact=`cat $config | grep "^contact" | cut -d= -f2`
  refresh=`cat $config | grep "^refresh" | cut -d= -f2`
  retry=`cat $config | grep "^retry" | cut -d= -f2`
  expire=`cat $config | grep "^expire" | cut -d= -f2`
  minimum=`cat $config | grep "^minimum" | cut -d= -f2`
  include=`cat $config | grep "^include" | cut -d= -f2`

  if [ -f ! $seqfile ]
        then echo 'Error !!!! the nameseq file is missing....'
             exit
  fi

  set `date`;

  m=$2
  y=$6
  d=$3

  # Make the month a numeric number

  case $m in
  Jan*)     m=01 ;;
  Feb*)     m=02 ;;
  Mar*)     m=03 ;;
  Apr*)     m=04 ;;
  May*)     m=05 ;;
  Jun*)     m=06 ;;
  Jul*)     m=07 ;;
  Aug*)     m=08 ;;
  Sep*)     m=09 ;;
  Oct*)     m=10 ;;
  Nov*)     m=11 ;;
  Dec*)     m=12 ;;
  *)        m=-1 ;;
  esac

  # Convert the single digit days into 2 digit numbers (ie, add a leading zero)

  case $d in

  1)        d=01;;
  2)        d=02;;
  3)        d=03;;
  4)        d=04;;
  5)        d=05;;
  6)        d=06;;
  7)        d=07;;
  8)        d=08;;
  9)        d=09;;
  esac

  # subtract 1900 from the year....

  y=`expr $y - 1900`

  cur_date=$y$m$d

  #  there is a file called 'nameseq' which should be in the current
  # directory.  It's a one line file that contains the last date (yymmdd)
  # and the last sequence for that date (0-99).  We now need to read that
  # file.  If the last date is different from today's, the sequence is set
  # to zero, and the new date is used.  If the date is the same (ie, running
  # it more than once on the same day) we just increase the sequence number
  #
  # At the end, I re-write the 'nameseq' file back out.

  set `cat $seqfile`; dateseq=$1; seq=$2

  if  [ $cur_date -le $dateseq ]
          then seq=`expr $seq + 1`
        else
             dateseq=$cur_date
             seq=0
  fi

  case $seq in

  0)  seq=00;;
  1)  seq=01;;
  2)  seq=02;;
  3)  seq=03;;
  4)  seq=04;;
  5)  seq=05;;
  6)  seq=06;;
  7)  seq=07;;
  8)  seq=08;;
  9)  seq=09;;
  esac

  # rewrite the 'nameseq' file back out

  echo $dateseq  $seq > $seqfile

  echo the date_seq is $dateseq and the seq is $seq

  # All of these variables are going to be inserted into the named.boot
  # file on the primary nameserver.

  echo ';'                                                        >  $output
  echo '; this file was created on' `date`                        >> $output
  echo ';'                                                        >> $output
  echo ';  Authoritative data for the ' $origin ' domain '        >> $output
  echo ';'                                                        >> $output
  echo '; For more information, contact:'                         >> $output
  echo ';        sysadmin:  ganis@draco'                          >> $output
  echo ';'                                                        >> $output
  echo '$origin' $origin                                          >> $output
  echo $origin '  IN  SOA ' $authns $contact ' ( '                >> $output
  echo '                 ' $dateseq$seq '   ; serial '            >> $output
  echo '                 ' $refresh '       ; refresh time '      >> $output
  echo '                 ' $retry '       ; retry on failure '    >> $output
  echo '                 ' $expire '        ; expire data '       >> $output
  echo '                 ' $minimum ')      ; minimum '           >> $output
  echo $origin '      IN    NS ' $authns                          >> $output
  echo $authns '      IN    A ' $authaddr                         >> $output
  echo '$''include ' $include                                     >> $output

  echo
  echo 'the new master files are in place.'
  echo
  echo 'should the named deamon be refreshed (y|n) ?'
  read answer

  if [ $answer = 'y' ]
      then  kill -HUP `cat /etc/named.pid`
  fi

