zoukankan      html  css  js  c++  java
  • python实现多个文件的分发

    之前写的脚本只能分发一个配置,每次分发多个配置总要执行很多次,很不爽,于是就有了这个脚本

    from multiprocessing import Process
    import paramiko
    import sys
    file = sys.argv[1::]
    Username = "root"
    Password = "123456"
    Dest_Path = [
    
        "/data/x5online/", #分发配置的目的地,这里测试只写了两个,可以自己加
        "/tmp/"
    
    ]
    Port = 22
    def sftpPut(ip):
        try:
            s = paramiko.Transport((ip,Port))
            s.connect(username=Username,password=Password)
            sftp = paramiko.SFTPClient.from_transport(s)
            for localFile in file:
                for remoteFile in Dest_Path:
                    sftp.put(localFile,remoteFile + localFile)
                print("%s put successful." %ip.strip())
        except:
            print("%s not exits."%ip.strip())
    def ipProcess():
        with open("ip.txt","r") as IP_file:
            for ip in IP_file.readlines():
                p = Process(target=sftpPut,args=(ip,))
                p.start()
    if __name__ == '__main__':
        ipProcess()
    

    其中ip.txt文件内容为:

    192.168.170.129
    192.168.170.150
    192.168.170.143
    

    用法:python "程序名称" 文件名1 文件名2 文件名3 文件名4

    天天向上,空杯心态。
  • 相关阅读:
    AGC002
    ICPC 北美Mid Central 2019 Regional
    【洛谷 5020】货币系统
    【洛谷 1109】学生分组
    【洛谷 2915】奶牛混合起来
    【洛谷 4162】最长距离
    【YCOJ 3805】竞选
    【洛谷 2807】最长路
    【洛谷 2918】买干草Buying Hay
    【LOJ 10172】涂抹果酱
  • 原文地址:https://www.cnblogs.com/uglyliu/p/6269024.html
Copyright © 2011-2022 走看看