#!/bin/bash public_hostname="pushmeto-123456789.us-east-1.elb.amazonaws.com" lastip_filename=/var/lib/bind/last-ip.txt log_filename=/var/log/update-ip.log update_key=/etc/bind/Kpushme.to.+157+12345.private while (:) do ip=`host -t a $public_hostname | cut -f 4 -d ' '` old_ip=`cat $lastip_filename` d=`date` if [ "$old_ip" = "$ip" ] then echo "$d ip is the same, $ip" >> $log_filename else echo "$d CHANGED. Was $old_ip, became $ip" >> $log_filename nsupdate_filename=/tmp/nsupdate.txt rm -f $nsupdate_filename echo "server 127.0.0.1" >> $nsupdate_filename echo "update delete pushme.to." >> $nsupdate_filename echo "update delete www.pushme.to." >> $nsupdate_filename echo "update add pushme.to. 300 IN A $ip" >> $nsupdate_filename echo "update add pushme.to. 300 MX 10 aspmx2.googlemail.COM." >> $nsupdate_filename # add more MX here and other @ records! echo "update add www.pushme.to. 300 IN A $ip" >> $nsupdate_filename echo "" >> $nsupdate_filename /usr/bin/nsupdate -k $update_key -d $nsupdate_filename >> $log_filename 2>&1 /usr/sbin/rndc freeze; /usr/sbin/rndc thaw echo $ip > $lastip_filename fi sleep 300 done