Scripts/dynpowerup: Difference between revisions

From fakedWiki
Jump to: navigation, search
(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…")
 
No edit summary
Line 1: Line 1:
This script will update the A records for zones you host on your local PowerDNS nameserver to your (external) dynamic IP.
I'm running this script after every reconnect of my VDSL link through ppp's ip-up scripts by putting it here:
<pre>
/etc/ppp/ip-up.d/dynpowerup
</pre>
<pre>
#!/bin/bash
#!/bin/bash


Line 25: Line 32:
   echo "IP updates done"
   echo "IP updates done"
fi
fi
</pre>

Revision as of 00:46, 9 February 2011

This script will update the A records for zones you host on your local PowerDNS nameserver to your (external) dynamic IP.

I'm running this script after every reconnect of my VDSL link through ppp's ip-up scripts by putting it here:

/etc/ppp/ip-up.d/dynpowerup
#!/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