homehowtokbslinksaboutcontactprojectsmusic

Index > Knowledge Base > Google Dynamic DNS
Update google domain name via API using shell script, update dns, log, uName, uPass, and domain to your enviornment
dns="192.168.1.1" # adjust if needed
log="/var/log/ddnsup.log" # adjust if needed
domain="" # domain name you want to search
cip=`dig @${dns} +short ${domain}` # current domain ip
nip=`dig +short myip.opendns.com @resolver1.opendns.com` # get external ip address
#nip=`wget -O - -o /dev/null http://icanhazip.com` # another way to get external ip address
if [ "${cip}" = "${nip}" ]
then
        res="No update needed for ${domain}"
else
        uName=""
        uPass=""
        res=`wget -O - -o /dev/null https://${uName}:${uPass}@domains.google.com/nic/update?hostname=${domain}&myip=${nip} > /dev/null 2>&1`
fi
dte=$(date +%F) # just for logging
ts=$(date +%T) # just for logging
echo "$dte $ts  | $res \n" >> $log
Then just add the cronjob
crontab -e
and paste the following at the end, this will run 3 times daily (8am, 2pm, 8pm)
0 8,14,20 * * * ddnsup