Bash 脚本中的 Nslookup

Nslookup in Bash Script

如何在 .sh 文件中获得带有 nslookup 的 dns mx 记录的结果,它会自动执行所有步骤而不询问 set type=mx 然后域。我只想执行 ./file.sh 然后它给我结果。

bash 文件可能是这样的:

#!/bin/bash
nslookup
set type=mx
example.com

但每次我执行该文件时,它只会运行第一行 nslookup,并再次请求 set type=mx 和域。

我使用 -q=mx:

以另一种方式在 Whosebug 中得到了答案
#!/bin/bash
nslookup -q=mx example.com

但我希望我的回答使用 set type=mx

试试这个:

echo -e "set type=mx\nexample.com" | nslookup

您很可能想使用 here-documents:

nslookup <<EOF
set type=mx
example.com
EOF