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