Dynamic DNS Checker


From Docunext Technology Wiki

Jump to: navigation, search
#!/bin/sh
DIFF="/tmp/ipdiff"
TMP1="/var/tmp/ip1"
TMP2="/var/tmp/ip2"
HOST="example.org"
FOUND="/var/tmp/found"
echo "found:" > $FOUND

if [ ! -e $TMP1 ] ; then
    host $HOST | awk '{print $4}' > $TMP1
    exit 0
else
    host $HOST | awk '{print $4}' > $TMP1
    diff $TMP1 $FOUND > $DIFF
    if [[ ! -s $DIFF ]] ; then
        cp $TMP1 $TMP2
        echo "$HOST not valid: `cat $TMP1`"
        exit 1
    fi;
    diff $TMP1 $TMP2 > $DIFF
    cp $TMP1 $TMP2
    if [[ -s $DIFF ]] ; then
        echo "DNS has changed."
        /bin/cat /etc/unbound/unbound.conf_bk  | /bin/sed s/zzzozzzozzz/`/bin/cat /var/tmp/ip1`/g > /etc/unbound/unbound.conf && /etc/init.d/unbound restart
        /sbin/iptables-restore /etc/iptables_save.txt
    else
        exit 0
    fi;
fi;
exit 0
Personal tools