Linux Shell Script

Linux Shell Script

This simple script allows to update dyndns.it / ddns.org host

#!/bin/sh
# Simple updater for dyndns.it
#
# 1 - Create a free dyndns.it host here: https://dyndns.it/order/?service=free&newone=1
# 2 - Configure your USERNAME, PASSWORD and HOST
# 3 - Execute in cron every 5 minutes
#
# note: adapted to dyndns.it from http://techgeekjay.blogspot.com/2013/03/no-ip-automatic-update-bash-script-for.html
#

USERNAME=--account name--
PASSWORD=--my password--
HOST=--my host name--

# no configuration needed under this line
#
LOGFILE=/var/log/dyndns.it.log
STOREDIPFILE=/var/run/current_ip
USERAGENT="Simple Shell dyndns.it Updater/0.4 supporto@supporto.email"

if [ ! -e $STOREDIPFILE ]; then
 touch $STOREDIPFILE
fi

NEWIP=$(curl http://icanhazip.com/)
STOREDIP=$(cat $STOREDIPFILE)

if [ "$NEWIP" != "$STOREDIP" ]; then
 RESULT=$(curl -o "$LOGFILE" -s --user-agent "$USERAGENT" "https://$USERNAME:$PASSWORD@update.dyndns.it/nic/update?hostname=$HOST&myip=$NEWIP")

 LOGLINE="[$(date +"%Y-%m-%d %H:%M:%S")] $RESULT"
 echo $NEWIP > $STOREDIPFILE
else
 LOGLINE="[$(date +"%Y-%m-%d %H:%M:%S")] No IP change"
fi

echo $LOGLINE >> $LOGFILE

exit 0