我需要在多台服务器上运行一个命令,我正在使用以下代码:
import paramiko, getpass, fileinput
username = raw_input("Enter your username [%s]: " % getpass.getuser())
passwd = getpass.getpass("Enter your password: ")
serverlist = raw_input("Enter the server list file path with filename: ")
for line in fileinput.input([serverlist]):
paramiko.util.log_to_file('paramiko.log')
s = paramiko.SSHClient()
#s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(line, 22, username, passwd)
stdin, stdout, stderr = s.exec_command('uptime')
print stdout.read()
s.close()
但是,此代码产生以下错误消息:
Traceback (most recent call last):
File "test_paramiko.py", line 15, in
s.connect(line, 22, username, passwd)
File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 277, in connect
socket.getaddrinfo(hostname, port):
socket.gaierror: [Errno -2] Name or service not known
我不确定我在这里缺少什么。请帮忙!