added new script update-hosts.sh

refreshes the dyndns ip of realm.mynetgear.com it it changes
This commit is contained in:
2020-08-05 09:05:59 +01:00
parent fa673cc5f8
commit a0fd02868f
+20
View File
@@ -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