Tuesday, October 26, 2010

Why I Love Shell-Scripting

For those times when you have a text file of host to IP bindings, it's easy to see if you need to add shit to your DNS servers. You can write a script like:

for i in `cat hosts.txt`
do
   HOSTIP=`echo $i | cut -d : -f 1`
   FOUNDNAME=`echo $i | cut -d : -f 2`
   DNSNAME=`dig -x ${HOSTIP} | egrep -v "^;" | awk '/PTR/{print $5}'`
   if [ "${DNSNAME}" = "" ]
   then
      DNSNAME="#NOT_IN_DNS#"
   fi
   printf "%-15s%-40s%-40s\n" ${HOSTIP} ${DNSNAME} ${FOUNDNAME}
done

That gives you output that looks like:

192.168.90.24    labserv1024u.labzone.net.        labserv1024u.labzone.net
192.168.90.3     labserv1003u.labzone.net.        labserv1003u.labzone.net
192.168.90.20    labserv1020u.labzone.net.        labserv1020u.labzone.net
192.168.90.6     labserv1006u.labzone.net.        labserv1006u.labzone.net
192.168.80.20    #NOT_IN_DNS#                     labserv3014u
192.168.80.19    #NOT_IN_DNS#                     labserv1301u
192.168.90.130   labserv1130u-90.labzone.net.     labserv1130u.labzone.net
192.168.7.73     labserv1073u.labzone.net.        
192.168.90.26    labserv1026u-90.labzone.net.     labserv1026u.labzone.net
192.168.90.27    labserv1027u-90.labzone.net.     labserv1027u.labzone.net
192.168.90.21    labserv1021u.labzone.net.        labserv1021u.labzone.net
192.168.2.132    labserv3132u.labzone.net.        labserv3132u
192.168.7.188    labserv1188u.labzone.net.        labserv1188u
192.168.2.131    labserv3131u.labzone.net.        labserv3131u
192.168.2.240    labserv3071u.labzone.net.        labserv3071u
192.168.10.13    #NOT_IN_DNS#                     labmgr13
192.168.90.18    labserv1018u.labzone.net.        labserv1018u.labzone.net
192.168.90.7     labserv1007u.labzone.net.        labserv1007u.labzone.net
192.168.90.10    labserv1010u-90.labzone.net.     labserv1010u.labzone.net
192.168.36.73    #NOT_IN_DNS#                     labserv1073u
192.168.36.72    #NOT_IN_DNS#                     labserv1072u
192.168.7.73     labserv1073u.labzone.net.        labserv1073u
192.168.90.16    labserv1016u-90.labzone.net.     labserv1016u.labzone.net
192.168.90.25    labserv1025u.labzone.net.        labserv1025u.labzone.net
192.168.90.19    labserv1019u.labzone.net.        labserv1019u.labzone.net
192.168.90.2     labserv1002u.labzone.net.        labserv1002u.labzone.net
192.168.90.4     labserv1004u.labzone.net.        labserv1004u.labzone.net
192.168.36.71    #NOT_IN_DNS#                     labserv1071u
192.168.7.186    labserv1186u.labzone.net.        labserv1186u
192.168.90.9     labserv1009u.labzone.net.        labserv1009u.labzone.net
192.168.90.8     labserv1008u.labzone.net.        labserv1008u.labzone.net
192.168.90.17    labserv1017u.labzone.net.        labserv1017u.labzone.net
192.168.90.1     labserv1001u.labzone.net.        labserv1001u.labzone.net
192.168.90.5     labserv1005u.labzone.net.        labserv1005u.labzone.net

Then, you just grep for the "#NOT_IN_DNS#" lines and update your DNS servers to reflect your host table file.

No comments:

Post a Comment