这是我的代码:
conn = SSH2()
conn.connect(host)
conn.authenticate(account)
print (conn.response)
conn.send('enable 8\n') <--------------first problem: execute("enable 8') does not work here. Can't understand why. I have to use send
conn.execute('somepassword')
print (conn.response)
conn.execute('term len 0') <--------------fore some reason the output for this command makes it to the outputs list that I am creating below
print (conn.response)
for command in commands:
print "Executing command", command
try:
conn.execute(command)
print (conn.response)
except:
e = sys.exc_info()[0]
output="Unsupported command or timeout"
outputs.append(output)概述:
上面没有提到-this,但是我必须启动脚本,它将在我的第一次运行中失败(超时),然后第二次尝试成功。
-why是不是授权不适用于执行?
-why,我的命令的输出似乎被延迟了吗?我的理解是,每次运行“execute(‘命令’)”时,exscript都会等待输出,然后才会执行下一个命令。
假设我有命令1,2,3,4
有时,我看到命令2和命令3的输出存储在一起,它们看起来像是由一个conn.response接收到的,而前面的conn.response是空的。
如有任何以上的帮助,我们将不胜感激。
发布于 2015-04-14 21:19:41
exscript邮件列表讨论了这个问题。为了完整起见,我也会在这里回答。
第一个问题:
由于某些原因,os猜测器没有正确识别设备,因此使用了通用驱动程序,而该驱动程序无法工作。这可以由将错误归档修复或手动设置驱动程序(在那种情况下是ios)。
第二个问题:
请不要执行密码(execute('somepassword'))!这可能会导致混乱。而是使用exscript身份验证/授权机制。
下列措施应能发挥作用:
from Exscript.util.interact import read_login
from Exscript.protocols import SSH2
account = read_login()
conn = SSH2()
# setting driver manually would be:
# conn = SSH2(manual_driver="ios")
conn.connect("host")
conn.authenticate(account)
conn.send('enable 8\n')
# if authorization password differs from login password
# you have to set it in account instance
account.set_authorization_password("<enable password>")
conn.app_authorize(account)
conn.autoinit()
outputs = []
for command in commands:
print "Executing command", command
try:
conn.execute(command)
output = conn.response
except:
e = sys.exc_info()[0]
output = "Unsupported command or timeout"
outputs.append(output)如果使用高级API执行脚本,这可能会更短。
https://stackoverflow.com/questions/28616012
复制相似问题