码迷,mamicode.com
首页 > 其他好文 > 详细

mitogen附带文件到远程主机

时间:2018-09-19 16:20:54      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:nload   color   bin   with   cep   file   call   hostname   load   

#!/usr/bin/env python
#
import mitogen.master
import mitogen.select
import subprocess
import logging
import mitogen.utils
import time
import os

def read_local():
    with open(/Users/Redheat/Downloads/cmake-3.12.1-Darwin-x86_64.dmg,rb) as f:
        return f.read()


def main(router):
    local = router.local(debug=True)
    file_content = local.call(read_local)
    hostnames = [192.168.101.25, 192.168.101.27, 192.168.101.29]
    remote_hosts = [router.ssh(hostname=hostname, username=root, check_host_keys=accept) for hostname in hostnames]
    rc = [remote_host.call(write_local,file_content) for remote_host in remote_hosts]
    print(Command return code was:, rc)

def write_local(file_content):
    with open(/tmp/cmake-3.12.1-Darwin-x86_64.dmg, wb) as f:
        f.write(file_content)

if __name__ == __main__:
    logging.basicConfig(level=logging.INFO)
    mitogen.utils.run_with_router(main)

 

mitogen附带文件到远程主机

标签:nload   color   bin   with   cep   file   call   hostname   load   

原文地址:https://www.cnblogs.com/redheat/p/9674679.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!