File: ch07.get_cache.sh

package info (click to toggle)
bind 1%3A8.4.6-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,752 kB
  • ctags: 22,385
  • sloc: ansic: 159,091; sh: 19,593; perl: 14,224; makefile: 5,554; yacc: 2,475; cpp: 2,154; csh: 848; awk: 753; tcl: 674; lex: 423; fortran: 240
file content (38 lines) | stat: -rwxr-xr-x 629 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh

ROOT=A.ROOT-SERVERS.NET.
TMPFILE=/tmp/ns.$$
CACHETMP=/tmp/db.cache.tmp

#
# Look up root server information and store it in a temporary file.
#
nslookup >$TMPFILE <<-EOF
server $ROOT
set type=ns
.
EOF

#
# Generate the the db.cache file from the nslookup output.  Store
# it in a temporary file.
#
cat $TMPFILE | awk '
  /(root)/ {printf "%-20s 99999999 IN  NS %s.\n", ".", $NF}
  /address/ {printf "%-20s 99999999 IN  A  %s\n", $1 ".", $NF}
  ' > $CACHETMP

#
# Move the new db.cache in place if it is not empty.
#
if test -s $CACHETMP
then
  mv $CACHETMP db.cache
else
  rm $CACHETMP
fi

#
# Clean up.
#
rm $TMPFILE