. /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)
#!/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 ;;
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 # <host> <zonefile>
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}."
done
}
+
run >> $logfile