Syed Jahanzaib Personal Blog to Share Knowledge !

November 19, 2015 DDNS Bash Script for Linux

Filed under: Linux Related — Tags: , , , — Syed Jahanzaib / Pinochio~:) @ 10:17 AM


Posting for personnel reference:

Following script was made to update ddns record at from Linux base pc using bash. I found script on net as well, but didn’t worked the way i wanted, So I made one myself. Simple yet effective!

# Script for Linux base systems using bash
# Created to suite local need in specific case. Well tested with CENTOS 6.x n UBUNTU 12.x
# Syed . Jahanzaib . aacable at hotmail dot com
# October , 2015
# Uncomment below to view debug log
# set -x

# Various variables, make sure to change the credentials and hostname as required.
# Temp files and log file to record updates if required

# If external ip text file not found, then create one
if [ ! -e "$EXTIP" ] ; then
touch "$EXTIP"

# Download current LIVE ip from intenret to match with old ip
wget -q -O /tmp/newip.txt
a=`cat $EXTIP`
b=`cat $NEWIP  | cut -f 2 -d "=" | cut -f 1 -d "-" -s | grep -m 1 ^`
if [[ $a != "$b" ]]

# changeip update now
curl "$URL=$b&u=$CIPUSER&p=$CIPPASS&hostname=$CIPHOST"

# Update New WAN IP in OLD File
echo $b > $EXTIP

# Print OLD vs New Comparision for REVIEW
echo Old IP = $a
echo New IP = $b
echo Update Time = $DATE
echo Update Done.

# Print OLD vs New Comparision for REVIEW in LOG FILE for later review
echo "*********************************************"  >> $LOG
echo New IP FOUND > $LOG
echo Old IP = $a >> $LOG
echo New IP found at $DATE and IP is = $b >> $LOG

# IF OLD and NEW ip are same, then no need to update, just EXIT
echo $DATE / No need to change IP. DDNS BASH Script / Powered by Syed Jahanzaib


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: