Files
root-scripts/update-hosts.sh
2021-04-07 09:06:16 +02:00

20 lines
559 B
Bash
Executable File

#!/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