想利用Threading实现并发,但是失败了。怀疑在多个线程下 con.expect( ) 为同一id,需要额外对con.expect 或 send 实现线程安全,因为总是报timeout,匹配不到字串。
为了防止多进程在读取设备列表时重复复制相同数据,又舍近求远用multiprocessing.Manager()折腾很久失败,没明白Manager().Queue()为什么会不成功。
#!/usr/bin/env python
#coding=utf-8"""
Collecting configuration with a jumpserver.
Yong Peng 2017-09-05
"""
import time
import pexpect
import os
import sys
import multiprocessing
#import getpass
__version__ = '3.0'
#time = time.strftime('%y.%m.%d-%H:%M:%S')
Dir_name = time.strftime('%Y%m%d')
if not os.path.lexists('/config_bak/{}'.format(Dir_name)):
os.system('mkdir /config_bak/{}'.format(Dir_name))
#登录堡垒机的帐号
#Password = getpass.getpass('Pls input password: ')
Username = 'usernameXX'
Pwd = 'passXX'
#登录设备的帐号
Login_user = 'usernameYY'
Login_pwd = 'passYY'
Enable_pwd = 'enableYY'
command_set1 = ['show run\n', 'show vlan\n', 'show interface status\n']
command_set2 = ['show run\n', 'show ap-config summ\n', 'show ap-config run\n']
command_set3 = ['dis curr \n', 'dis interface brief\n&#