我有一个包含以下内容的 10 行文本文件:
Linux Server myhostname on mount point /var is XX% full
我想在每一行为 myhostname 做一个 nslookup,提取服务器的 IP 地址并在每一行填满后插入它...关于如何完成的任何建议?
最佳答案
nslookup
已弃用,我什至无法在我的系统上安装它,但命令 host
可以帮助您。
使用这个:
while read -r line
do
ip=$(host $(echo $line | cut -f 3 -d ' ') | head -n 1 | cut -f 4 -d ' ')
echo $line $ip >> newhosts
done < hosts
运行此命令后,我的 newhosts
如下所示:
Linux Server google.se on mount point /var is XX% full 216.58.209.99
Linux Server stackoverflow.com on mount point /var is XX% full 151.101.1.69
Linux Server yahoo.se on mount point /var is XX% full 74.6.136.150
Linux Server flashback.org on mount point /var is XX% full 212.85.75.180
在此之后,您可以调用 mv newhosts hosts
关于linux - 在每一行上使用 nslookup 并插入到特定列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48102273/