Paramiko and simple multi-process

Source: Internet
Author: User

Paramiko specifically not much to say, see other information

Yum Insatll python-devel

1.PyCrypto Installation

TAR-XF pycrypto-2.6.1.tar.gzcd pycrypto-2.6.1/python setup.py build && python setup.py install

2.ECDSA Installation

Unzip PYTHON-ECDSA-MASTER.ZIPCD Python-ecdsa-masterpython setup.py Install

3.paramiko Installation

Unzip PARAMIKO-MASTER.ZIPCD Paramiko-masterpython setup.py build && python setup.py install

4. Error:

>>> Import Paramiko/usr/lib64/python2.6/site-packages/crypto/util/number.py:57:powminsecurewarning:not  Using Mpz_powm_sec.  You should rebuild using LIBGMP >= 5 to avoid timing attack vulnerability.  _warn ("Not using MPZ_POWM_SEC. You should rebuild using LIBGMP >= 5 to avoid timing attack vulnerability. ", powminsecurewarning) >>> exit ()

5. Simple Multi-process:

#!/usr/bin/python   import paramiko  import osimport sysimport  Timeimport multiprocessingimport datetimeip_list = []def execmd (Host,cmd):     time.sleep (2)     hostname=host    username= "Ckl"     ssh=paramiko. Sshclient ()     ssh.load_system_host_keys ()     privatekey =  Os.path.expanduser ('/home/chenkangle/key/ckl.pem ')     key = paramiko. Rsakey.from_private_key_file (Privatekey)     ssh.connect (hostname=hostname,username= Username,pkey = key)     stdin,stdout,stderr=ssh.exec_command (cmd)      print stdout.read ()     ssh.close () Def upfile (Host_ip,local_path, Remote_path):     time.sleep (2)     privatekey =  Os.path.expanduser ('/hoMe/ckl/.ssh/id_rsa ')     key=paramiko. Rsakey.from_private_key_file (Privatekey)     scp = paramiko. Transport ((host_ip, 22))     scp.connect (username= ' Ckl ',  pkey=key)      sftp = paramiko. Sftpclient.from_transport (SCP)     src = local_path    des  = remote_path    file=os.path.basename (SRC)     print  ' = ' *50    print  ' start to upload file %s  '  %  Datetime.datetime.now ()     print  ' upload file: ',file     Sftp.put (Local_path,remote_path)     scp.close ()     print  ' \033[1; 32m upload file success %s \033[0m '  % datetime.datetime.now ()      print  ' = ' *50def downfile (host_ip,remote_paTh,local_path):     privatekey = os.path.expanduser ('/home/chenkangle/key/ckl.pem ')     key=paramiko. Rsakey.from_private_key_file (Privatekey)     scp = paramiko. Transport ((host_ip, 22))     scp.connect (username= ' Ckl ',  pkey=key)      sftp = paramiko. Sftpclient.from_transport (SCP)     src = remote_path    file= Os.path.basename (src)     des = local_path    print  ' = ' * 50    print  ' start to download file %s  '  %  Datetime.datetime.now ()     print  ' download file: ',file     Sftp.get (Src,des)     scp.close ()     print  ' \033[1;32m  download file success %s \033[0m '  % datetime.datetimE.now ()     print  ' = ' *50def all_ip ():     f = file (' 2.txt ', ' R ')     c = f.readlines ()     for x in  C:        ip = x.split (' \ n ') [0]         ip_list.append (IP)     f.close () if __name__== ' __main__ ':     ALL_IP ()     pool = multiprocessing. Pool (processes=30)     threads = []    print  "Begin ... "    for i in ip_list:          #pool. Apply_async (Execmd, (I,))         pool.apply_async (Upfile, (i , '/home/chenkangle/php_0420.tar.gz ', '/tmp/soft/php_0420.tar.gz '))     pool.close ()      pool.join ()     foR res in threads:        print res.get ()      print  "Process done."

6. Description:

2.txt is a list file

The contents are as follows:

10.1.1.110.1.1.210.1.1.3 ....

Control the processes running concurrently through the process Pool poll bulk Operations processes=30

This article is from the "OPS rookie" blog, please be sure to keep this source http://ckl893.blog.51cto.com/8827818/1766228

Paramiko and simple multi-process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.