home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / NETWORK / ISP / bind.4.8.3.lzh / BIND483 / EXAMPLES / ch13.check_soa.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1994-01-09  |  2KB  |  79 lines

  1. #!/bin/sh
  2. if test "$1" = ""
  3. then
  4.     echo usage: $0 domain
  5.     exit 1
  6. fi
  7. DOMAIN=$1
  8. #
  9. # Use nslookup to discover the nameservers for this domain ($1).
  10. # Use awk to grab the name server names from the nameserver lines.
  11. # (The names are always in the last field).  Use sort -u to weed out
  12. # duplicates; we don't actually care about collation.
  13. #
  14. SERVERS=`nslookup -type=ns $DOMAIN |\
  15.                  awk '/nameserver/ {print $NF}' | sort -u`
  16. if test "$SERVERS" = ""
  17. then
  18.     #
  19.     # Didn't find any servers.  Just quit silently; nslookup will
  20.     # have detected this error and printed a message.  That will 
  21.     # suffice.
  22.     #
  23.     exit 1
  24. fi
  25. #
  26. # Check each server's SOA serial number.  The output from 
  27. # nslookup is saved in two tmp files: nso.$$ (standard output) 
  28. # and nse.$$ (standard error).  These files are rewritten on
  29. # every iteration.  Turn off defname and search since we
  30. # should be dealing with fully qualified names.
  31. #
  32. # NOTE: this loop is rather long; don't be fooled.
  33. #
  34. for i in $SERVERS
  35. do
  36.   nslookup >/tmp/nso.$$ 2>/tmp/nse.$$ <<-EOF
  37.     server $i
  38.     set nosearch
  39.     set nodefname
  40.     set norecurse
  41.     set q=soa
  42.     $DOMAIN
  43. EOF
  44.   #
  45.   # Does this response indicate that the current server ($i) is
  46.   # authoritative?  The server is NOT authoritative if (a) the
  47.   # response says so, or (b) the response tells you to find
  48.   # authoritative info elsewhere.
  49.   #
  50.   if egrep "Non-authoritative|Authoritative answers can be" \
  51.                                           /tmp/nso.$$ >/dev/null
  52.   then
  53.     echo $i is not authoritative for $DOMAIN
  54.     continue
  55.   fi
  56.   #
  57.   # We know the server is authoritative; extract the serial number.
  58.   #
  59.   SERIAL=`cat /tmp/nso.$$ | grep serial | sed -e "s/.*= //"`
  60.   if test "$SERIAL" = ""
  61.   then
  62.     #
  63.     # We get here if SERIAL is null.  In this case, there should
  64.     # be an error message from nslookup; so cat the "standard 
  65.     # error" file.
  66.     #
  67.     cat /tmp/nse.$$
  68.   else
  69.     #
  70.     # Report the server's name and its serial number.
  71.     #
  72.     echo $i has serial number $SERIAL
  73.   fi
  74. done  # end of the "for" loop
  75. #
  76. # Delete the temporary files.
  77. #
  78. rm -f /tmp/nso.$$ /tmp/nse.$$
  79.