I have a duplicate in DNS record when adding new instance. My goal is to use "nsupdate" to be able to delete A record by IP if new instance IP is found. This is what I did. However, it didn't delete any duplicate when ran this script. what will be the best walk around?
domain=${domainname}
nodename=(hostname | awk -F. '{print $1}')
local_ip=$(ifconfig eth0 | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')
nslookup ${local_ip} | grep SERVFAIL
if [[ $? < 0 ]] ; then
echo "Record already exists"
echo -e "update ${local_ip} IN A"
else
echo "creating forward Record: ${codename}.${domain}"
echo -e "update add ${nodename}.${domain} 3600 A ${local_ip}\nsend" | nsupdate -g
fi