import multiprocessing
import time,datetime
def Ssh_Cmd(host,CmdFile):
elog = open('error.log','a+')
log = open('7z.log',"a+")
for Cmd in open(CmdFile).readlines():
Cmd = Cmd.strip()
if not len(Cmd) or Cmd.startswith('#'):
continue
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(hostname=host,port=22,username='root',password='password',timeout=10)
except Exception,e:
print 'connnet Fail %s' % host
elog.write('%s'%host)
elog.close()
continue
else:
print 'connnet Ok %s' % host
stdin,stdout,stderr=ssh.exec_command(Cmd)
log.write(stdout.read())
log.close()
starttime = datetime.datetime.now()
if __name__ == "__main__":
os.remove('7z.log')
os.remove('error.log')
IplistFile='iplist.txt'
CmdFile='config'
result = []
pool = multiprocessing.Pool(processes=8)
for host in open(IplistFile).readlines():
pool.apply_async(Ssh_Cmd,(host,CmdFile,))
pool.close()
pool.join()
print 'Done'
endtime = datetime.datetime.now()
print "time span",endtime-starttime
python multiprocessing多进程 ssh
原创
©著作权归作者所有:来自51CTO博客作者120113541的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
java 多进程 内存 jvm多进程
理解的结论: 一个进程可以拥有多个线程。 一个程序可以有多个进程(多次执行,也可以没有进程,不执行) &n
java 多进程 内存 JVM 服务器 端口号