0
我想获得主机列表的输出,使用unix命令NSLOOKUP +主机列表,但我得到一个错误,虽然它确实工作,当我只有一个主机。Python,使用基本的unix命令和主机列表
有没有更简单的方法来做我正在做的事情,或者你能帮我修复这个简单的脚本吗?
我的脚本是:
#!/usr/bin/python
import commands, os, string
hostname = ['host1', 'host2']
response = commands.getoutput("nslookup " + ' '.join(hostname))
print response
错误:
[email protected] ~/scripts> ./nslookup
^CTraceback (most recent call last):
File "./nslookup", line 6, in <module>
response = commands.getoutput("nslookup " + ' '.join(hostname))
File "/usr/lib64/python2.6/commands.py", line 46, in getoutput
return getstatusoutput(cmd)[1]
File "/usr/lib64/python2.6/commands.py", line 56, in getstatusoutput
text = pipe.read()
KeyboardInterrupt
感谢奏效,忘了for循环= { } – aznjonn