#!/bin/sh #set -x out=hosts.dns echo -e "##### `date`\n127.0.0.1\tlocalhost\n##### from dns">$out { cat /etc/hosts egrep '^[a-zA-Z0-9]' tw.hosts echo "ls math.duke.edu"|nslookup echo "ls xxxx.duke.edu"|nslookup echo "ls yyyy.duke.edu"|nslookup } | awk '{ if($1 ~ /^(152|127)/){# hosts table: ip nickname officalname comments if(!N[$2]){N[$2]=$1;} # pick the 1st one only for(i=3;i<=NF;i++){ if(!F[$i] && $i ~ /\./){F[$i]=$2;break;} } }else if ($NF ~ /^\//){ # tw.hosts: hostname ostype dir if(!N[$1] && !F[$1]){ # not in host table TM[++tm]=$1; } TN[$1]=1; }else if ($1 ~ /ORIGIN/ && $2 ~ /\.$/){ # nslookup: $ORIGIN domain dnm=substr($2,1,length($2)-1); printf("##### %s\n",dnm)>>h; }else if ($NF ~ /^152/ && $1 ~ /^[a-zA-Z][a-zA-Z0-9]*$/){ # nslookup: nickname ip fn=$1 "." dnm; if(!N[$1]){# nickname not in hosts table M[++m]=$NF "\t" $1 " " fn; }else if(N[$1] != $NF){ # nicks IP differ # !G[$1] && ID[$1]=$NF; } G[$1]=1; if(!TN[$1] && !TN[fn]){ DN[++dn]=$1 "\t\t" fn; } printf("%s\t%s %s\n",$NF,$1,fn)>>h; } }END{ printf("##### NOT IN HOST TABLE:\n"); for(i=1;i<=m;i++){ printf("%s\n",M[i]); } printf("##### IP IN HOST TABLE DIFF FROM DNS:\n"); for(i in ID){ printf("%s\t%s <- %s\n",N[i],i,ID[i]); } printf("##### EXTRA HOSTNAMES IN HOST TABLE:\n"); for(i in N){ if(!G[i] && N[i]){ printf("%s\t%s\n",N[i],i); } } printf("##### TW.HOSTS NOT IN HOST TABLE:\n"); for(i=1;i<=tm;i++){ printf("%s\t%s\n",N[TM[i]],TM[i]); } printf("##### DNS HOSTS NOT IN TW.HOSTS:\n"); for(i=1;i<=dn;i++){ printf("%s\n",DN[i]); } }' h=$out - mv $out $out.$$ && sort -t. +0n -1 +1n -2 +2n -3 +3n -4 $out.$$ >$out && rm -f $out.$$