38 lines
796 B
Bash
Executable File
38 lines
796 B
Bash
Executable File
#!/bin/sh
|
|
|
|
cache=.update_ip.cache
|
|
server=ns1.example.com
|
|
zone=dyn.example.com
|
|
host=desktop
|
|
secret=""
|
|
|
|
ip=$(wget -4 -q -O - http://treehouse.org.za/ip)
|
|
#set_ip=$(dig +short -t a ${host}.${zone})
|
|
set_ip=$(nslookup -type=a ${host}.${zone} | awk '/^Address: / { print $2 }')
|
|
|
|
if [ -z ${ip} ] || [ -z ${cache} ]; then
|
|
exit;
|
|
fi
|
|
|
|
if [ -f "${HOME}/${cache}" ]; then
|
|
old_ip=$(cat "${HOME}/${cache}")
|
|
fi
|
|
|
|
if [ "${set_ip}" = "${ip}" ] && [ "${ip}" = "${old_ip}" ]; then
|
|
exit;
|
|
else
|
|
rm -f "${HOME}/${cache}"
|
|
echo "${ip}" > "${HOME}/${cache}"
|
|
fi
|
|
|
|
cat <<EOF | nsupdate
|
|
server ${server}
|
|
zone ${zone}.
|
|
key ${host}.${zone} ${secret}
|
|
update delete ${host}.${zone}. A
|
|
update delete ${host}.${zone}. TXT
|
|
update add ${host}.${zone}. 60 A $ip
|
|
update add ${host}.${zone}. 60 TXT "Updated on $(date)"
|
|
send
|
|
EOF
|