20 lines
559 B
Bash
20 lines
559 B
Bash
#!/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 |