--- /dev/null
+#!/bin/bash
+
+zonefile=$1
+host=$2
+watchfile=$3
+
+
+function getAddrFromZonefile # <host> <zonefile>
+{
+ egrep "^$1\\s.*\\sA\\s.*" $2 | egrep -o "([0-9]+\.)+[0-9]+"
+}
+
+function setAddrInZonefile # <host> <zonefile> <addr>
+{
+ sed -i -e "s_^\\($1\\s.*A\\s.*\\s\\)\\([0-9]\\+\\.\\)\\+[0-9]\\+_\\1$3_g" "$2"
+}
+
+function getSerialFromZonefile # <zonefile>
+{
+ awk '/; serial/{print$1}' "$1"
+}
+
+function setSerialInZonefile # <zonefile> <serial>
+{
+ sed -i -e "s_^\\(.*\\s\\)[0-9]\+\\(\\s\\+; serial.*\\)_\\1$2\\2_g" "$1"
+}
+
+while true; do
+ inotifywait -q -e close_write "${watchfile}"
+ oldip=`getAddrFromZonefile "${host}" "${zonefile}"`
+ newip=`cat ${watchfile}`
+ echo -n "`date '+%a %F %T'` :: ${oldip} => ${newip}."
+
+ if ! [ "${oldip}" = "${newip}" ]; then
+ serial=`getSerialFromZonefile "${zonefile}"`
+ serial=$(( $serial + 1))
+ echo -n " Update IP address. New serial ${serial}."
+ setAddrInZonefile "${host}" "${zonefile}" "${newip}"
+ setSerialInZonefile "${zonefile}" "${serial}"
+ nsdc rebuild && nscd reload && nscd notify
+ fi
+ echo ""
+done
+
+
--- /dev/null
+$TTL 3h
+@ IN SOA ns1.sthu.org. shuber2.gmx.at. (
+ 2 ; serial number
+ 28800 ; Refresh
+ 7200 ; Retry
+ 864000 ; Expire
+ 86400 ; Min TTL
+ )
+
+ NS ns1.sthu.org.
+ NS ns2.sthu.org.
+
+
+sthu.org. IN A 37.247.49.68
+ns1 IN A 37.247.49.68
+euklid IN A 2.3.4.5
+euklid2 IN A 1.2.3.43
+ns2 IN A 174.37.196.55 ; ns2.afraid.org
+www IN CNAME sthu.org.