SSHClient是一个简单的包装类,围绕着Paramiko中的更底层功能。该API文档列出
recv_exit_status()的方法
Channel类。
一个非常简单的演示脚本:
import paramikoimport getpasspw = getpass.getpass()client = paramiko.SSHClient()client.set_missing_host_key_policy(paramiko.WarningPolicy())client.connect('127.0.0.1', password=pw)while True: cmd = raw_input("Command to run: ") if cmd == "": break chan = client.get_transport().open_session() print "running '%s'" % cmd chan.exec_command(cmd) print "exit status: %s" % chan.recv_exit_status()client.close()执行示例:
$ python sshtest.pyPassword: Command to run: truerunning 'true'exit status: 0Command to run: falserunning 'false'exit status: 1Command to run: $



