how to get console output from a remote computer (ssh + python)
Have you tried an even simpler approach?
>>> from subprocess import Popen, PIPE>>> stdout, stderr = Popen(['ssh', 'user@remote_computer', 'ps -ef'],... stdout=PIPE).communicate()>>> print(stdout)
Granted, this only works because I have ssh-agent
running preloaded with a private key that the remote host knows about.
child = pexpect.spawn("ssh user@remote_computer ps -ef")print "connecting..."i = child.expect(['user@remote_computer\'s password:'])child.sendline(user_password)i = child.expect([' .*']) #or use i = child.expect([pexpect.EOF])if i == 0: print child.after # uncomment when using [' .*'] pattern #print child.before # uncomment when using EOF patternelse: print "Unable to capture output"Hope this help..