昨天帮同事写的脚本,由于只实现了基础功能没考虑过多其它,同事反馈运行很慢,由于时间原因当时没考虑处理大数据的情况,结果没有通过大数据的考验,程序运行了72分钟才出结果j_0013.gif

需求:

1.A表和B表匹配,找出A表中不存在于B表中的域名,称为结果C
2.将结果C中的域名进行解析,得出对应解析IP,称为结果D
3.将结果D得到的IP与公司IP进行匹配,筛选出属于公司IP的域名,得到最终结果E

补充需求:最后数据为可以正常访问的域名。

wKioL1mbxFbxTAFHAAAVG6AC2g8878.png

于是今天将代码做了一些优化和调整:


#This Program design by jerry_jiang (copyright@(2011-2019)
#!/bin/bash
rm baobiao3.txt baobiao2.txt baogao.txt baobiao.txt c.txt jxip.txt tmp.ym 1&>/dev/null
awk 'FNR==NR{a[$0];next}!($0 in a)' b.txt a.txt >c.txt    

for line in `cat -A c.txt`
 do
 ym=`echo $line |cut -d"^" -f1`
 ip=`nslookup "www."$ym -timeout=0.01 |grep "Address: "|head -n 1|awk '{print $2}'`
 echo "$ym" "$ip" >>jxip.txt
done
#cat tmp.ym |awk '{print $5$6}'|sed -n 's#(#  #p' |sed -n 's#)# #p'|awk 'BEGIN{print "域名   IP地址"} {print$1 "   " $2}'>jxip.txt
for line in `cat -A ip.txt`
 do
  ip=`echo $line |cut -d"^" -f1`
  grep  $ip  jxip.txt >>baobiao.txt
done
cat baobiao.txt |sort|uniq >baobiao2.txt
for line in `cat -A baobiao2.txt| awk '{print $1}'`
  do
  ym=`curl -sI $line |grep "200 OK"|awk '{print $3}'|cat -A |cut -d"^" -f1`
  [ "$ym" = "OK" ]  &&  echo  $line >>baobiao3.txt
done
awk 'BEGIN{print "域名"} {print $1 }' baobiao3.txt >baogao.txt

脚本最终输出数据为baogao.txt文件,其它为文件为程序临时生成文件,保留是了排错,听同事说有特殊情况,因此保留数据做备。

       听同事说他每天要花一个小时重复此项工作,因此写了此脚本,脚本基本实现了其需求,脚本中还有许多改进和优化的地方,多指教。

优化后大数据测试效果:t_0023.gif

wKiom1mbxUPjMoXmAABo9UswXwg050.jpg