即时连接linux服务器和sshclient。然后,我通过此服务器上的telnet连接cisco路由器。我正在连接服务器并完美地执行telnet命令,但是在第二个或第三个telnet命令代码被卡住并且没有抛出错误。这是我的代码的一部分:
mydata <- structure(list(Date = structure(c(4L, 4L, 3L, 3L, 3L, 2L,
2L, 2L, 1L), .Label = c("2016-05-01", "2016-06-01", "2016-07-01",
"2016-08-01"), class = "factor"), Price = c(5000L, 4300L, 7000L,
4500L, 3000L, 3900L, 2700L, 2900L, 7100L), Postnr = c(101L, 103L,
105L, 105L, 103L, 101L, 103L, 105L, 101L)), .Names = c("Date",
"Price", "Postnr"), row.names = c(NA, 9L), class = "data.frame")
为什么它会卡在这个命令上?我该怎么处理呢?
答案 0 :(得分:0)
我想我需要查看更多代码才能找到错误的内容。如果您没有特定的理由需要使用Paramiko频道,如果您只使用Paramiko客户端,生活可能会更容易。这是我的一个旧剧本的粗略片段:
def ssh_connect(usr, pswds, host):
# Open Connection - auto add policy
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Retry with multiple passwords
for pswd in pswds:
try:
ssh.connect(host, username=usr, password=pswd)
return ssh
except:
pass
else:
print("Could not login to: " + host)
return None
def send_command(conn, command):
try:
stdin, stdout, stderr = conn.exec_command(command)
if stdout:
for str in stdout:
sys.stdout.write("\t%s" % str)
return True
if stderr:
for str in stderr:
sys.stderr.write("\t%s" % str)
return False
else:
print("\n")
return True
except paramiko.ssh_exception.SSHException as e:
print(e.message)
return False
当然,请打电话给他们:
conn = ssh_connect(login, passwords, host)
send_command(conn, command)