Dynhost updater auto


script :

#/bin/sh
#
# CONFIG
#
HOST=DOMAINE_NAME
LOGIN=LOGIN
PASSWORD=PASSWORD
PATH_LOG=/var/log/dynhost
CURRENT_DATE=`date`
#
# GET IPs
#
HOST_IP=`dig +short $HOST`
CURRENT_IP=`curl -4 ifconfig.co`
#
# DO THE WORK
#
if [ -z $CURRENT_IP ] || [ -z $HOST_IP ]
then
echo « No IP retrieved » >> $PATH_LOG
else
if [ « $HOST_IP » != « $CURRENT_IP » ]
then
echo « $CURRENT_DATE » »: Current IP: » « $CURRENT_IP » « and » « host IP: » « $HOST_IP »  » IP has changed! » >> $PATH_LOG
RES=`curl –user « $LOGIN:$PASSWORD » « https://www.ovh.com/nic/update?system=dyndns&hostname=$HOST&myip=$CURRENT_IP »`
echo « Result request dynHost: » >> $PATH_LOG
echo « $RES » >> $PATH_LOG
else
echo « $CURRENT_DATE » »: Current IP: » « $CURRENT_IP » « and » « Host IP: » « $HOST_IP »  » IP has not changed » >> $PATH_LOG
fi
fi

dynhost-ovh

A simple (cron) script to update DynHost on OVH hosting

Prerequisites

This script works with two linux commands : curl and dig. If you do not have the dig you must install it from the package « dnsutils » :

sudo apt-get update
sudo apt-get install dnsutils

How to use

  1. Download the dynhost.sh script and put it in the folder /etc/cron.hourly (to check every hour)
  2. Add execution permissions to file : chmod +x dynhost.sh
  3. Modify the script with variables : HOST, LOGIN, PASSWORD

How it works

  1. The command dig is used to retrieve the IP address of your domain name.
  2. The command curl (with the website ifconfig.co) is used to retrieve the current public IP address of your machine.
  3. The two IPs are compared and if necessary a curl command to OVH is used to update your DynHost with your current public IP address.

,