Scripts/dynpowerup

From fakedWiki
Revision as of 00:45, 9 February 2011 by Jan (talk | contribs) (Created page with "#!/bin/bash RECORDS=("example.com" "ns1.example.com" "ns2.example.com" "example.org" "example.net") DBUSER="your-powerdns-user" DBPASS="your-powerdns-password" DBNAME="your-pow…")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  1. !/bin/bash

RECORDS=("example.com" "ns1.example.com" "ns2.example.com" "example.org" "example.net")

DBUSER="your-powerdns-user" DBPASS="your-powerdns-password" DBNAME="your-powerdns-database"

IP=`lynx -dump http://checkip.dyndns.org | awk '{print $4}'`

if [ -e "/tmp/nsup.IP" ]; then

 read OLD_IP < "/tmp/nsup.IP"

else

 OLD_IP="0.0.0.0"

fi

if [ "$IP" != "$OLD_IP" ]; then

 echo "IP address changed from $OLD_IP to $IP"
 for RECORD in ${RECORDS[@]}; do
   echo "updating record: $RECORD"
   COMMAND="$COMMAND UPDATE ${DBNAME}.records SET content = \"$IP\" WHERE name = \"$RECORD\";"
 done
 mysql -u${DBUSER} -p${DBPASS} ${DBNAME} -e "$COMMAND"
 echo "$IP" > /tmp/nsup.IP
 echo "IP updates done"

fi