1 | #!/bin/sh
|
---|
2 | # $Id: fetchzone.sh 9970 2012-02-15 18:04:47Z rick $
|
---|
3 | #
|
---|
4 | # Wireless Leiden specific configuration to fetch DNS zones
|
---|
5 | # used by MaraDNS
|
---|
6 | #
|
---|
7 |
|
---|
8 | # Script is running in deamon mode to discriptors available, so make sure to
|
---|
9 | # close them to avoid 'hanging' scripts.
|
---|
10 | exec <&-
|
---|
11 | exec 1>/dev/null
|
---|
12 | exec 2>/dev/null
|
---|
13 |
|
---|
14 |
|
---|
15 | # Updates of $ZONES we are going to fetch from the $SERVER every $IDLE seconds
|
---|
16 | ZONES="wleiden.net. 16.172.in-addr.arpa. 17.172.in-addr.arpa.
|
---|
17 | 18.172.in-addr.arpa. 19.172.in-addr.arpa. 20.172.in-addr.arpa.
|
---|
18 | 21.172.in-addr.arpa. 22.172.in-addr.arpa. 23.172.in-addr.arpa.
|
---|
19 | 24.172.in-addr.arpa. 25.172.in-addr.arpa. 26.172.in-addr.arpa.
|
---|
20 | 27.172.in-addr.arpa. 28.172.in-addr.arpa. 29.172.in-addr.arpa.
|
---|
21 | 30.172.in-addr.arpa. 31.172.in-addr.arpa."
|
---|
22 | SERVER=172.16.4.46
|
---|
23 | IDLE=3600
|
---|
24 |
|
---|
25 | LOGFILE=/var/log/fetchzone.log
|
---|
26 | PIDFILE=/var/run/fetchzone.pid
|
---|
27 | ### END OF USER CONFIGURABLE VARIABLES ###
|
---|
28 |
|
---|
29 | TAGNAME=`basename $0 .sh`
|
---|
30 | # Create logging service
|
---|
31 | log() {
|
---|
32 | echo `date "+%b %e %T"`":" $* >> ${LOGFILE}
|
---|
33 | echo $* | logger -t "$TAGNAME"
|
---|
34 | }
|
---|
35 |
|
---|
36 | # Register PID
|
---|
37 | PID=$$
|
---|
38 | echo ${PID} > ${PIDFILE}
|
---|
39 | log "[INFO] Fetchzone starting with PID: $PID"
|
---|
40 |
|
---|
41 | # Make me a deamon script
|
---|
42 | while [ true ]; do
|
---|
43 |
|
---|
44 | CHANGED_ZONES=""
|
---|
45 | # Run through multiple zones
|
---|
46 | for ZONE in ${ZONES}; do
|
---|
47 | # (re) Set some extra vars
|
---|
48 | TMPFILE=/tmp/dns-tmp-${ZONE}
|
---|
49 | REALFILE=/usr/local/etc/maradns/db.${ZONE}
|
---|
50 | # Execute Fetchzone
|
---|
51 | /usr/local/bin/fetchzone ${ZONE} ${SERVER} > ${TMPFILE}
|
---|
52 |
|
---|
53 | # Did Fetchzone exit unhappy
|
---|
54 | if [ $? -ne 0 ]; then
|
---|
55 | # Something went wrong lets log it
|
---|
56 | log "[ERROR] [$ZONE] Errors found in fetchzone query"
|
---|
57 | continue
|
---|
58 | fi
|
---|
59 |
|
---|
60 | # Are there any changes, we need to put active?
|
---|
61 | cmp -s ${TMPFILE} ${REALFILE}
|
---|
62 | if [ $? -ne 0 ]; then
|
---|
63 | log "[INFO] [$ZONE] Changes found"
|
---|
64 | cp ${TMPFILE} ${REALFILE}
|
---|
65 | CHANGED_ZONES="$CHANGED_ZONES $ZONE"
|
---|
66 | fi
|
---|
67 | done
|
---|
68 |
|
---|
69 | # Maradns requires a restart to load new zonefile
|
---|
70 | if [ -n "$CHANGED_ZONES" ]; then
|
---|
71 | log "[INFO] `/usr/local/etc/rc.d/maradns restart`"
|
---|
72 | fi
|
---|
73 |
|
---|
74 | # Next run in $IDLE seconds
|
---|
75 | sleep ${IDLE}
|
---|
76 | done
|
---|
77 |
|
---|