From a0fd02868f0d1c73cf9aba1d50e854f94a6172a9 Mon Sep 17 00:00:00 2001 From: Gorden Mende Date: Wed, 5 Aug 2020 09:05:59 +0100 Subject: [PATCH] added new script update-hosts.sh refreshes the dyndns ip of realm.mynetgear.com it it changes --- update-hosts.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 update-hosts.sh diff --git a/update-hosts.sh b/update-hosts.sh new file mode 100644 index 0000000..a865421 --- /dev/null +++ b/update-hosts.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# path to hosts file +hostsFile="/etc/hosts" + +# get old puppet hosts entry +oldIP=`cat ${hostsFile} | grep puppet | cut -d" " -f1` + +# get new ip +newIP=`dig realm.mynetgear.com +short` + +# check if newIP is different and change hosts entry +if [ ${newIP} != ${oldIP} ]; then + echo "Updating hosts file" | logger + sed -ie "/${oldIP}/d" "${hostsFile}"; + echo "${newIP} realm.mynetgear.com realm" >> ${hostsFile} + echo "${newIP} puppet.realm.local puppet" >> ${hostsFile} +else + echo "IP still up-to-date. Nothing to do, exiting." | logger +fi \ No newline at end of file