0

我可以使用 paramiko 打开一个 ssh 会话进入 switch。能够输入命令并获得相应的输出。我的问题是我想同时在交换机中输入许多命令。但是在输入新命令之前,想知道之前的命令是否成功输入到交换机中。例如

switch>enable switch# switch#config t switch(config) 输入第二个命令,直到我看到#符号和第三个命令,直到我看到配置。以下是我正在使用的代码

import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('ip-address',username='username', password='password')
list =['enable','config t']
command = '\n'.join(list)
#for i in range(len(list)):
print command
stdin,stdout,stderr = ssh.exec_command(command)
print(stdout.read())
4

1 回答 1

0

use interactive invoke shell

##invoke interactive shell chan = ssh.invoke_shell(); chan.send(command + '\n') ;
while not chan.recv_ready(): print 'waiting for challenge' time.sleep(1) ;       
resp = chan.recv(1024)  ;  print resp
于 2013-04-25T05:32:38.280 回答