added new script update-hosts.sh
refreshes the dyndns ip of realm.mynetgear.com it it changes
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user