pexpect-pxssh-登陆Linux-执行命令

#!/usr/bin/python
import pexpect
import pxssh
try:
    remote=pxssh.pxssh()
    hostname=raw_input('hostname:')
    username=raw_input('username:')
    password=raw_input('password:')
    remote.login(hostname,username,password)
    remote.sendline('cd /opt/autotest/')
    remote.prompt()
    remote.sendline('ll')
    remote.prompt()
    print remote.before
    print('成功了吧')
    remote.logout() 
except pxssh.ExceptionPxssh,e:
    print'pxssh failed on login'
    print str(e)
原文地址:https://www.cnblogs.com/boheyixia/p/5007143.html