Skip to content

Instantly share code, notes, and snippets.

@Serranya
Last active December 21, 2020 08:57
Show Gist options
  • Save Serranya/d9b98e1b69da8df71a2a to your computer and use it in GitHub Desktop.
Save Serranya/d9b98e1b69da8df71a2a to your computer and use it in GitHub Desktop.
Update script for dynamic dns.
#! /bin/bash
MYIP=$(wget -qO - http://myexternalip.com/raw)
USER=Redacted
PASSWORD=Redacted
HOST=Redacted
if [ ! -f /var/run/last.ip ]
then echo $MYIP > /var/run/last.ip
curl -s -X GET "https://nic.ChangeIP.com/nic/update?u=$USER&p=$PASSWORD&myip=$MYIP&hostname=$HOST&set=1"
fi
if ! cmp -s /var/run/last.ip <(echo $MYIP)
then curl -s -X GET "https://nic.ChangeIP.com/nic/update?u=$USER&p=$PASSWORD&myip=$MYIP&hostname=$HOST&set=1"
echo $MYIP > /var/run/last.ip
fi
sleep 30s
NEWIP=$(dig $HOST | tail -n 9 | grep $HOST | cut -f5)
if [ "$MYIP" != "$NEWIP" ]
then rm /var/run/last.ip
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment