7 --log) logfile
=$2; shift ;;
9 echo "$0 [-f] [--log logfile] zonefile host watchfile"
21 [ -z "${logfile}" ] && logfile
="/var/log/nsd-dynipwatch-${host}.log"
23 echo "logfile: ${logfile}"
27 function getAddrFromZonefile
# <host> <zonefile>
29 egrep "^$1\\s.*\\sA\\s.*" $2 |
egrep -o "([0-9]+\\.)+[0-9]+"
32 function setAddrInZonefile
# <host> <zonefile> <addr>
34 sed -i -e "s_^\\($1\\s.*A\\s.*\\s\\)\\([0-9]\\+\\.\\)\\+[0-9]\\+_\\1$3_g" "$2"
37 function getSerialFromZonefile
# <zonefile>
39 awk '/; serial/{print$1}' "$1"
42 function setSerialInZonefile
# <zonefile> <serial>
44 sed -i -e "s_^\\(.*\\s\\)[0-9]\+\\(\\s\\+; serial.*\\)_\\1$2\\2_g" "$1"
50 inotifywait
-q -e close_write
"${watchfile}" > /dev
/null
51 oldip
=`getAddrFromZonefile "${host}" "${zonefile}"`
52 newip
=`cat ${watchfile}`
53 echo "`date '+%a %F %T'` :: ${oldip} => ${newip}."
55 if ! echo "${newip}" |
egrep -q "^([0-9]+\\.)+[0-9]+$" ; then
56 echo "Wrong format of new IP address."
60 if ! [ "${oldip}" = "${newip}" ]; then
61 serial
=`getSerialFromZonefile "${zonefile}"`
62 serial
=$
(( $serial + 1))
63 echo " Update IP address. New serial ${serial}."
64 setAddrInZonefile
"${host}" "${zonefile}" "${newip}"
65 setSerialInZonefile
"${zonefile}" "${serial}"
66 nsdc rebuild
&& nsdc reload
&& nsdc notify