Last active
December 21, 2020 08:57
-
-
Save Serranya/d9b98e1b69da8df71a2a to your computer and use it in GitHub Desktop.
Update script for dynamic dns.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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