]>
git.sthu.org Git - shutils.git/blob - nsd/nsd-dynipwatch
8 --log) logfile
=$2; shift ;;
9 --watchfile) watchfile
=$2; shift ;;
11 echo "$0 [--log logfile] [--watchfile /tmp/\${host}.ip] zonefile host"
22 [ -z "${watchfile}" ] && watchfile
=/tmp
/${host}.ip
23 [ -z "${logfile}" ] && logfile
="/var/log/nsd-dynipwatch-${host}.log"
26 echo "Watch ${watchfile} for host ${host} and update ${zonefile}. Logfile: ${logfile}"
29 function getAddrFromZonefile
# <host> <zonefile>
31 egrep "^$1\\s.*\\sA\\s.*" $2 |
egrep -o "([0-9]+\\.)+[0-9]+"
34 function setAddrInZonefile
# <host> <zonefile> <addr>
36 sed -i -e "s_^\\($1\\s.*A\\s.*\\s\\)\\([0-9]\\+\\.\\)\\+[0-9]\\+_\\1$3_g" "$2"
39 function getSerialFromZonefile
# <zonefile>
41 awk '/; serial/{print$1}' "$1"
44 function setSerialInZonefile
# <zonefile> <serial>
46 sed -i -e "s_^\\(.*\\s\\)[0-9]\+\\(\\s\\+; serial.*\\)_\\1$2\\2_g" "$1"
53 inotifywait
-q -t 30 -e close_write
"${watchfile}" > /dev
/null
55 [ "$ret" = "0" ] ||
continue
57 oldip
=`getAddrFromZonefile "${host}" "${zonefile}"`
58 newip
=`cat ${watchfile}`
59 echo "`date '+%a %F %T'` :: ${oldip} => ${newip}."
61 if ! echo "${newip}" |
egrep -q "^([0-9]+\\.)+[0-9]+$" ; then
62 echo "Wrong format of new IP address."
66 if ! [ "${oldip}" = "${newip}" ]; then
67 serial
=`getSerialFromZonefile "${zonefile}"`
68 serial
=$
(( $serial + 1))
69 echo " Update IP address. New serial ${serial}."
70 setAddrInZonefile
"${host}" "${zonefile}" "${newip}"
71 setSerialInZonefile
"${zonefile}" "${serial}"
72 nsdc rebuild
&& nsdc reload
&& nsdc notify