利用sshpass和ssh编写脚本远程执行命令
发表于:2024-11-26 作者:热门IT资讯网编辑
编辑最后更新 2024年11月26日,import subprocessimport os(rfd, wfd) = os.pipe()arg = "-d%d" % rfdtry:p = subprocess.Popen(["sshpass
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")