0698afcaad5b4c291f4cd32ab87e74774c4c4c16
8 function getAddrFromZonefile
# <host> <zonefile>
10 egrep "^$1\\s.*\\sA\\s.*" $2 |
egrep -o "([0-9]+\.)+[0-9]+"
13 function setAddrInZonefile
# <host> <zonefile> <addr>
15 sed -i -e "s_^\\($1\\s.*A\\s.*\\s\\)\\([0-9]\\+\\.\\)\\+[0-9]\\+_\\1$3_g" "$2"
18 function getSerialFromZonefile
# <zonefile>
20 awk '/; serial/{print$1}' "$1"
23 function setSerialInZonefile
# <zonefile> <serial>
25 sed -i -e "s_^\\(.*\\s\\)[0-9]\+\\(\\s\\+; serial.*\\)_\\1$2\\2_g" "$1"
29 inotifywait
-q -e close_write
"${watchfile}"
30 oldip
=`getAddrFromZonefile "${host}" "${zonefile}"`
31 newip
=`cat ${watchfile}`
32 echo -n "`date '+%a %F %T'` :: ${oldip} => ${newip}."
34 if ! [ "${oldip}" = "${newip}" ]; then
35 serial
=`getSerialFromZonefile "${zonefile}"`
36 serial
=$
(( $serial + 1))
37 echo -n " Update IP address. New serial ${serial}."
38 setAddrInZonefile
"${host}" "${zonefile}" "${newip}"
39 setSerialInZonefile
"${zonefile}" "${serial}"
40 nsdc rebuild
&& nscd reload
&& nscd notify