Python 官方文档:入门教程 => 点击学习
import multiprocessingimport time,datetimedef ssh_Cmd(host,CmdFile): elog = open('error.log','a+') log = o
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
--结束END--
本文标题: python multiprocessi
本文链接: https://lsjlt.com/news/190264.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0