Advertisement
Guest User

Script to update DNS on AWS ELB

a guest
Apr 29th, 2010
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.41 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. public_hostname="pushmeto-123456789.us-east-1.elb.amazonaws.com"
  4. lastip_filename=/var/lib/bind/last-ip.txt
  5. log_filename=/var/log/update-ip.log
  6. update_key=/etc/bind/Kpushme.to.+157+12345.private
  7.  
  8.  
  9. while (:)
  10. do
  11.         ip=`host -t a $public_hostname | cut -f 4 -d ' '`
  12.         old_ip=`cat $lastip_filename`
  13.         d=`date`
  14.  
  15.         if [ "$old_ip" = "$ip" ]
  16.         then
  17.                 echo "$d ip is the same, $ip" >> $log_filename
  18.         else
  19.                 echo "$d CHANGED. Was $old_ip, became $ip" >> $log_filename
  20.         nsupdate_filename=/tmp/nsupdate.txt
  21.                 rm -f $nsupdate_filename
  22.                 echo "server 127.0.0.1" >> $nsupdate_filename
  23.                 echo "update delete pushme.to." >> $nsupdate_filename
  24.                 echo "update delete www.pushme.to." >> $nsupdate_filename
  25.  
  26.                 echo "update add pushme.to. 300 IN A $ip" >> $nsupdate_filename
  27.                 echo "update add pushme.to. 300 MX 10 aspmx2.googlemail.COM." >> $nsupdate_filename
  28.         # add more MX here and other @ records!
  29.  
  30.                 echo "update add www.pushme.to. 300 IN A $ip" >> $nsupdate_filename
  31.                 echo "" >> $nsupdate_filename
  32.  
  33.                 /usr/bin/nsupdate -k $update_key  -d $nsupdate_filename >> $log_filename 2>&1
  34.                 /usr/sbin/rndc freeze; /usr/sbin/rndc thaw
  35.                 echo $ip > $lastip_filename
  36.         fi
  37.  
  38.         sleep 300
  39. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement