Saturday, August 8, 2015

QNAP: add dnsomatic cronjob

Source: http://forum.qnap.com/viewtopic.php?t=12970
vi /share/CACHEDEV1_DATA/homes/dnsomatic/dnsomatic.sh
#!/bin/sh
HOSTNAME="all.dnsomatic.com"
USER="my_dnsomatic_user"
PASS="my_dnsomatic_password"
TMPFILE="/tmp/dnsomatic.oldip"
DATENOW=$(date)
 
IP=$(/sbin/curl -s http://myip.dnsomatic.com)
if [ -r "/tmp/dnsomatic.oldip" ]; then
 OLDIP=`cat /tmp/dnsomatic.oldip`
 if [ "$OLDIP" = "$IP" ]; then
  echo "IPs match; no update"
  exit 0
 else
  RETURN=$(/sbin/curl -s -m 60 -k -u ${USER}:${PASS} https://updates.dnsomatic.com/nic/update?hostname=${HOSTNAME}&myip=$IP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG)
  echo "Return message of DNS-O-Matic : " $RETURN
  echo $RETURN | grep "good" > /dev/null 2>&1
  if [ "$?" -eq "0" ]; then
   echo $IP > /tmp/dnsomatic.oldip
  else
   echo "" > /tmp/dnsomatic.oldip
  fi
 fi
else
 touch /tmp/dnsomatic.oldip
fi
Then update crontab to run it once an hour:
 vi /etc/config/crontab
0 */1 * * * /share/CACHEDEV1_DATA/homes/dnsomatic/dnsomatic.sh >/tmp/dnsomatic.log 2>&1
crontab /etc/config/crontab
/etc/init.d/crond.sh restart