From b5da071a06041527f6d47580f7c9ecd3de97a2a9 Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Mon, 29 Oct 2012 12:16:11 +0100 Subject: [PATCH] nsd-dynipwatch: --watchfile, let inotifywatch die --- init.d/nsd-dynipwatch | 3 +-- nsd-dynipwatch | 14 ++++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/init.d/nsd-dynipwatch b/init.d/nsd-dynipwatch index 9696359..d7563da 100755 --- a/init.d/nsd-dynipwatch +++ b/init.d/nsd-dynipwatch @@ -16,8 +16,7 @@ . /lib/lsb/init-functions PIDFILE=/var/run/nsd-dynipwatch.pid -IPFILE=/tmp/euklid.ip -ARGS="/etc/nsd3/sthu.org.zone euklid ${IPFILE}" +ARGS="/etc/nsd3/sthu.org.zone euklid" case "$1" in start) diff --git a/nsd-dynipwatch b/nsd-dynipwatch index a002f95..bfdb840 100755 --- a/nsd-dynipwatch +++ b/nsd-dynipwatch @@ -1,12 +1,14 @@ #!/bin/bash logfile= +watchfile= while true; do case $1 in --log) logfile=$2; shift ;; + --watchfile) watchfile=$2; shift ;; -h|--help) - echo "$0 [-f] [--log logfile] zonefile host watchfile" + echo "$0 [--log logfile] [--watchfile /tmp/\${host}.ip] zonefile host" exit 0 ;; *) break ;; @@ -17,11 +19,11 @@ done zonefile=$1 host=$2 -watchfile=$3 +[ -z "${watchfile}" ] && watchfile=/tmp/${host}.ip [ -z "${logfile}" ] && logfile="/var/log/nsd-dynipwatch-${host}.log" -echo "logfile: ${logfile}" +echo "Watch ${watchfile} for host ${host} and update ${zonefile}. Logfile: ${logfile}" function getAddrFromZonefile # @@ -47,7 +49,10 @@ function setSerialInZonefile # function run() { while true; do - inotifywait -q -e close_write "${watchfile}" > /dev/null + inotifywait -q -t 30 -e close_write "${watchfile}" > /dev/null + ret=$? + [ "$ret" = "0" ] || continue + oldip=`getAddrFromZonefile "${host}" "${zonefile}"` newip=`cat ${watchfile}` echo "`date '+%a %F %T'` :: ${oldip} => ${newip}." @@ -68,5 +73,6 @@ function run() done } + run >> $logfile -- 2.39.5