others - linux-将参数传递到Awk命令

我正在写一个脚本来检查域名黑名单,并查看哪些域名仍然有效(解析为IP ),以便从列表中删除旧的非解析域名,这个列表有数百万行,所以,我使用awk(替代do while read)来提高速度。

我试图写一个awk语句,将一个域名列表重新定位到一个列表,并且只打印解析的域名列表。

我几乎完成了,我该如何指定nslookup使用的服务器?


awk '{print $1}' /etc/pihole/gravity.list | nslookup -port=54| awk '/[Nn]ame/ {print $NF}' >> /etc/pihole/gravityProcessed.list




awk '{print $1}' /etc/pihole/gravity.list | nslookup 1.1.1.1 | awk '/[Nn]ame/ {print $NF}' >> /etc/pihole/gravityProcessed.list



问题是nslookup没有-server参数(它有-port参数),所以我需要awk来做:


nslookup [INSERT HOST] server -port=



这是/etc/pihole/gravity.list的例子


google.com


yahoo.com


skype.com


microsoft.com



另一个选项是当脚本命中不正确的域名时,正确的域名正规表达式,就像通过grep (?=^.{4,253}$)(^(?:[a-zA-Z0-9](?:(?:[a-zA-Z0-9-]){0,61}[a-zA-Z0-9])?.)+[a-zA-Z]{2,}$)

时间:


$ nslookup < gravity.list


Default Server: cdns01.comcast.net


Address: 2001:558:feed::1



> Non-authoritative answer:


Server: cdns01.comcast.net


Address: 2001:558:feed::1



Name: google.com


Addresses: 2607:f8b0:4009:80f::200e


 172.217.8.174



> Non-authoritative answer:


Server: cdns01.comcast.net


Address: 2001:558:feed::1



Name: yahoo.com


Addresses: 2001:4998:58:1836::11


 2001:4998:c:1023::5


 2001:4998:58:1836::10


 2001:4998:44:41d::3


 2001:4998:c:1023::4


 2001:4998:44:41d::4


 98.137.246.7


 98.138.219.231


 72.30.35.9


 72.30.35.10


 98.137.246.8


 98.138.219.232



> Non-authoritative answer:


Server: cdns01.comcast.net


Address: 2001:558:feed::1



DNS request timed out.


 timeout was 2 seconds.


Name: skype.com


Addresses: 23.102.255.237


 40.115.34.155


 40.121.80.200


 104.40.50.126



> Non-authoritative answer:


Server: cdns01.comcast.net


Address: 2001:558:feed::1



DNS request timed out.


 timeout was 2 seconds.


Name: microsoft.com


Addresses: 13.77.161.179


 40.76.4.15


 40.112.72.205


 40.113.200.201


 104.215.148.63



> $



如果要使用其他名称服务器,请查看nslookup的以下指令:

ARGUMENTS
在以下情况下输入交互模式:
1.当没有给出参数时(将使用默认名称服务器)
2.当第一个参数是连字符(-),第二个参数是名称服务器的主机名或Internet地址。

所以尝试


nslookup - 1.1.1.1 < /etc/pihole/gravity.list 2>/dev/null | 


 awk '/[Nn]ame/ {print $NF}' >> /etc/pihole/gravityProcessed.list



...