Python multithreaded bulk Remote management program

Source: Internet
Author: User

Python multithreaded Batch remote management program

#!/usr/bin/env Python # This script comes from Beijing Oldboy trainning.
# e_mail:70271111@qq.com # function:remote multi exec cmd by SSH.    
# version:1.1 ################################################ # Oldboy trainning info. # QQ 80042789 70271111 # site:http://www.etiantian.org # blog:http://oldboy.blog.51cto.com # Oldboy trainning QQ group:20
8160987 45039636 ################################################ Import multiprocessing import Os,sys import time result = [] f = file (' client.txt ') cmd = sys.argv[1] Excution_list = [] for line in F.readlines (): F_line = Line.strip (). Split () host = f_line[0] username = f_line[1] Port = f_line[2] if f_line[3] = = ' PASSWORD ': Pass
        Word = f_line[4] call_ssh = ' python batch_ssh.py%s%s PASSWORD%s '% (host,username,port,password,cmd) Print Call_ssh else:call_ssh = ' python batch_ssh.py%s%s%s Ssh_key%s '% (host,username,port,cmd) exc Ution_list.append (CALL_SSH) def run_cmd (ruN_task): Os.system (run_task) #print excution_list p = multiprocessing. Pool (Processes=len (excution_list)) for task in Excution_list:result.append (P.apply_async (Run_cmd, (Task,)) P.close ( ) for R in Result:r.get (timeout=10)

Client.txt is the IP username password list for the server

batch_ssh.py content See http://oldboy.blog.51cto.com/2561410/1221129

This article is from the "Old boy Linux operation" blog, please be sure to keep this source http://oldboy.blog.51cto.com/2561410/1221605

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.