背景: 手里有一个列表,里面含有我们维护的机器,地址域名等等信息,但个别信息不准确,列表上千条;如何确认地址和域名是否正确?不能一个个ping吧;于是顺手写了个shell,可以通过下面方式输出;
#!/bin/bash
# this is to test ip and domain weather equal
for I in `cat iplist2.log`
do
ipaddr=`echo $I | awk -F--- '{print $1}'`
doname=`echo $I | awk -F--- '{print $2}'`
realip=`ping -c 1 $doname | grep "PING"|awk -F[\(,\)] '{print $2}'`
if [ $ipaddr == $realip ]
then
check="OK"
else
check="NO"
fi
echo "$doname-----$realip========$ipaddr=========$check"
done