--- /dev/null
+#!/bin/sh -e
+### BEGIN INIT INFO
+# Provides: nsd-dynipwatch
+# Required-Start: $nsd3
+# Required-Stop: $nsd3
+# Should-Start: $local_fs
+# Should-Stop: $local_fs
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: Start nsd dynip update
+# Description: Provides an updater for NSD3 zone files
+### END INIT INFO
+
+
+
+. /lib/lsb/init-functions
+
+PIDFILE=/var/run/nsd-dynipwatch.pid
+IPFILE=/tmp/euklid.ip
+ARGS="/etc/nsd3/sthu.org.zone euklid ${IPFILE}"
+
+case "$1" in
+start)
+ start-stop-daemon --start --quiet --background --pidfile $PIDFILE --make-pidfile --exec /usr/local/bin/nsd-dynipwatch -- $ARGS
+ ;;
+stop)
+ start-stop-daemon --stop --quiet --pidfile $PIDFILE
+ ;;
+restart)
+ start-stop-daemon --stop --retry 5 --quiet --pidfile $PIDFILE
+ start-stop-daemon --start --quiet --background --pidfile $PIDFILE --make-pidfile --exec /usr/local/bin/nsd-dynipwatch -- $ARGS
+ ;;
+status)
+ status_of_proc -p $PIDFILE /usr/local/bin/nsd-dynipwatch nsd-dynipwatch && exit 0 || exit $?
+ ;;
+*)
+ log_action_msg "Usage: /etc/init.d/cron {start|stop|restart}"
+ exit 2
+ ;;
+esac
+exit 0
+
--- /dev/null
+#!/bin/bash
+
+logfile=
+
+while true; do
+ case $1 in
+ --log) logfile=$2; shift ;;
+ -h|--help)
+ echo "$0 [-f] [--log logfile] zonefile host watchfile"
+ exit 0
+ ;;
+ *) break ;;
+ esac
+ shift
+done
+
+
+zonefile=$1
+host=$2
+watchfile=$3
+[ -z "${logfile}" ] && logfile="/var/log/nsd-dynipwatch-${host}.log"
+
+echo "logfile: ${logfile}"
+
+
+
+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"
+}
+
+function run()
+{
+ while true; do
+ inotifywait -q -e close_write "${watchfile}" > /dev/null
+ oldip=`getAddrFromZonefile "${host}" "${zonefile}"`
+ newip=`cat ${watchfile}`
+ echo "`date '+%a %F %T'` :: ${oldip} => ${newip}."
+
+ if ! echo "${newip}" | egrep "^([0-9]+\\.)+[0-9]+$" ; then
+ echo "Wrong format of new IP address."
+ continue
+ fi
+
+ if ! [ "${oldip}" = "${newip}" ]; then
+ serial=`getSerialFromZonefile "${zonefile}"`
+ serial=$(( $serial + 1))
+ echo " Update IP address. New serial ${serial}."
+ setAddrInZonefile "${host}" "${zonefile}" "${newip}"
+ setSerialInZonefile "${zonefile}" "${serial}"
+ nsdc rebuild && nsdc reload && nsdc notify
+ fi
+ done
+}
+
+run >> $logfile
+
+++ /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
-
-
$TTL 3h
@ IN SOA ns1.sthu.org. shuber2.gmx.at. (
- 2 ; serial number
+ 1 ; serial number
28800 ; Refresh
7200 ; Retry
864000 ; Expire
sthu.org. IN A 37.247.49.68
ns1 IN A 37.247.49.68
-euklid IN A 2.3.4.5
+euklid IN A 1.2.3.42
euklid2 IN A 1.2.3.43
ns2 IN A 174.37.196.55 ; ns2.afraid.org
www IN CNAME sthu.org.
+++ /dev/null
-#!/bin/sh
-
-curl www.sthu.org/whatismyip.html