标签:line client pcl 运维 exp class shel 自己 脚本
之前线上服务器分发配置都是用shell和expect脚本分发,脚本写了很长,上周换了ansible,现在自己用python写一个,就30行代码就可以实现需求,之前的shell写了快200行了,蛋疼,代码如下:
from multiprocessing import Process import paramiko import sys file = sys.argv[1] Username = "root" Password = "123456" Dest_Path = [ "/data/x5online/%s" %file, "/tmp/%s" %file ] Port = 22 def sftpPut(ip): try: s = paramiko.Transport((ip,Port)) s.connect(username=Username,password=Password) sftp = paramiko.SFTPClient.from_transport(s) localFile = file for remoteFile in Dest_Path: sftp.put(localFile,remoteFile) print("%s put successful." %ip) except: print("%s not exits."%ip) def ipProcess(): for i in range(10,40): ip = ‘192.168.170.%s‘%i p = Process(target=sftpPut,args=(ip,)) p.start() if __name__ == ‘__main__‘: ipProcess()
鸡汤一回,对python感兴趣了,学的才快,就像去年对linux很痴迷,一年时间,现在的我是一家游戏公司的运维负责人。加油
标签:line client pcl 运维 exp class shel 自己 脚本
原文地址:http://www.cnblogs.com/uglyliu/p/6187978.html