我对python相当陌生,我尝试创建一个简单的ssh会话并运行一个简单的命令。 我知道我可以使用“paramiko”,但我决定使用pexpect/pxsh并安装了最后一个版本。在
我的代码:
#!/usr/bin/env python
from pexpect import *
import pexpect
import pxssh
import getpass
import time
import os
try:
s = pexpect.pxssh()
hostname = raw_input('hostname:')
username = raw_input('usernmae:')
s.login((hostnmae,username,password)
s.sendline ('uptime')
s.prompt()
print s.before
s.sendline ('ls -l')
s.prompt()
print s.before
s.logout()
except pxssh.ExceptionPxssh, e:
print "pxssh failed"
print str(e)
但它失败的原因如下:
^{pr2}$有人能帮忙吗?在
非常感谢!在
您的代码中存在各种问题:
应该是的
检查额外的“(”和变量
hostname
在线。在在上面的代码行之前,您需要ssh的密码。在
相关问题 更多 >
编程相关推荐