首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ssh时exscript的多个问题:延迟输出、延迟启动连接、授权问题

使用ssh时exscript的多个问题:延迟输出、延迟启动连接、授权问题
EN

Stack Overflow用户
提问于 2015-02-19 20:13:02
回答 1查看 661关注 0票数 0

这是我的代码:

代码语言:javascript
复制
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是空的。

如有任何以上的帮助,我们将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-14 21:19:41

exscript邮件列表讨论了这个问题。为了完整起见,我也会在这里回答。

第一个问题:

由于某些原因,os猜测器没有正确识别设备,因此使用了通用驱动程序,而该驱动程序无法工作。这可以由将错误归档修复或手动设置驱动程序(在那种情况下是ios)。

第二个问题:

请不要执行密码(execute('somepassword'))!这可能会导致混乱。而是使用exscript身份验证/授权机制。

下列措施应能发挥作用:

代码语言:javascript
复制
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执行脚本,这可能会更短。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28616012

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档