bash - Bash 脚本中的 Nslookup

标签 bash shell stdin heredoc nslookup

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

bash 文件可能是这样的:

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

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

我通过使用 -q=mx 以另一种方式在 stackoverflow 中得到了答案:

#!/bin/bash
nslookup -q=mx example.com

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

最佳答案

试试这个:

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

关于bash - Bash 脚本中的 Nslookup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41384764/

相关文章:

bash - 在 bash 中退出并显示错误消息(在线)

bash - 将 grep 计数分配给变量

linux - 我怎样才能得到这个月的最后一天 Shell 脚本

linux - 如何只替换 Perl 中 IP 地址的前三个八位字节

linux - 在多次 sed 运行中获取重复条目

python - sys.stdin.readlines() 挂起 Python 脚本

c - 如何确定嵌入式环境中的行尾?

linux - BusyBox tar : append workaround given limited disk space?

c - 在 lex 中只接受来自键盘的一个输入

node.js - 将句柄向下传递到管道