utility-scripts/update_ip.sh

36 lines
673 B
Bash
Raw Normal View History

2015-06-15 00:06:23 +00:00
#!/bin/sh
cache=.update_ip.cache
server=ns1.example.com
zone=dyn.example.com
host=desktop
secret=""
2015-07-08 08:29:53 +00:00
ip=$(wget -q -O - http://treehouse.org.za/ip)
2016-11-29 19:20:05 +00:00
set_ip=$(dig +short ${host}.${zone})
2015-06-15 00:06:23 +00:00
if [ -z ${ip} ] || [ -z ${cache} ]; then
exit;
fi
if [ -f "${HOME}/${cache}" ]; then
old_ip=$(cat "${HOME}/${cache}")
fi
2016-11-29 19:20:05 +00:00
if [ "${set_ip}" = "${ip}" ] && [ "${ip}" = "${old_ip}" ]; then
2015-06-15 00:06:23 +00:00
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}.
update add ${host}.${zone}. 60 A $ip
update add ${host}.${zone}. 60 TXT "Updated on $(date)"
send
EOF