import subprocess
import os
(rfd, wfd) = os.pipe()
arg = "-d%d" % rfd
try:
p = subprocess.Popen(["sshpass",arg,"ssh","-l","haohzhang","phxaishdc9dn1447.stratus.phx.ebay.com","ls","/tmp/"], stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
os.close(rfd)
os.write(wfd,"PASSWORD\n")
os.close(wfd)
stdout, stderr = p.communicate()
print stdout, stderr
except OSError:
print("to use the ‘ssh‘ connection type with passwords, you must install the sshpass program")
本文出自 “Linux运维” 博客,转载请与作者联系!
原文地址:http://haohaozhang.blog.51cto.com/9176600/1833107