首页 > 其他 > 详细

利用sshpass和ssh编写脚本远程执行命令

时间:2016-08-01 23:14:39      阅读:358      评论:0      收藏:0      [点我收藏+]

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运维” 博客,转载请与作者联系!

利用sshpass和ssh编写脚本远程执行命令

原文:http://haohaozhang.blog.51cto.com/9176600/1833107

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!