首页 > 代码库 > python脚本分发bash升级包案例--参考
python脚本分发bash升级包案例--参考
#!/usr/bin/env python #encoding:utf-8 #paramiko import paramiko import sys,os import threading import multiprocessing import time iplist = {‘192.168.1.10‘:‘123456‘,‘192.168.2.10‘:‘321456‘,‘192.168.13.10‘:‘111111‘} user = ‘root‘ host = ‘‘ password = ‘‘ bit = ‘‘ pakg = ‘‘ s = paramiko.SSHClient() s.load_system_host_keys() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) number = 0 def ssh_install(): cmd = ‘rpm -Uvh /tmp/shell_update.rpm‘ s.connect(host,22,user,password,timeout=1) stdin,stdout,stderr = s.exec_command(cmd) cmd_result = stdout.read(),stderr.read() print ‘======%s--%sbit======‘ %(host,bit) for line in cmd_result: print line, print ‘‘ s.close() def ssh_bit(): global bit cmd = ‘getconf LONG_BIT‘ s.connect(host,22,user,password,timeout=1) stdin,stdout,stderr = s.exec_command(cmd) cmd_result = stdout.read(),stderr.read() bit = int(str(cmd_result[0]).strip()) s.close() def ssh_copy(): global pakg t = paramiko.Transport((host,22)) t.connect(username=user,password=password) sftp = paramiko.SFTPClient.from_transport(t) sftp.put(pakg,‘/tmp/shell_update.rpm‘ ) t.close() def run(ipinfo): global pakg global host global password global bit host = ipinfo[0] password = ipinfo[1] ssh_bit() if bit == 64: pakg = ‘/tmp/bash-3.2-33.el5_11.4.x86_64.rpm‘ ssh_copy() ssh_install() elif bit == 32: pakg = ‘/tmp/bash-3.2-33.el5_11.4.i386.rpm‘ ssh_copy() ssh_install() if len(iplist.items()) < 10: process_number = len(iplist.items()) else: process_number = 10 pool = multiprocessing.Pool(processes=process_number) for info in iplist.items(): pool.apply_async(run,(info,)) pool.close() pool.join()
本文出自 “Chocolee” 博客,谢绝转载!
python脚本分发bash升级包案例--参考
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。