Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Script to update DNS on AWS ELB

By: a guest on Apr 29th, 2010  |  syntax: Bash  |  size: 1.41 KB  |  views: 588  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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