#!/usr/bin/env python#encoding:utf-8#paramikoimport paramikoimport sys,osimport threadingimport multiprocessingimport timeiplist = {' 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 = 0def ssh_install (): cmd = ' RPM&NBSP;-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 &NBSP;&NBSP;GLOBAL&NBSP;BIT&NBSP;&NBSP;HOST&NBSP;=&NBSP;IPINFO[0]&NBSP;&NBSP;PASSWORD&NBSP;=&NBSP;IPINFO[1] ssh_bit () if bit == 64: pakg = '/tmp/ bash-3.2-33.el5_11.4.x86_64.rpm ' ssh_copy () &nBsp; 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 = 10pool = multiprocessing. Pool (Processes=process_number) for info in iplist.items (): pool.apply_ Async (Run, (info)) pool.close () pool.join ()
This article from "Chocolee" blog, declined reprint!
Python Script Distribution Bash upgrade package case--Reference