參數:
1.securtcrt的session目錄
2.一個xshell的模版文件
3.輸出目錄(必須不存在,自動創建)
#!/usr/bin/python # -*- coding:utf-8 -*- #轉換secrt的session文件到xshell的session文件 import os from sys import * def gen_xshell_session(path, tpl_file, out_session): os.mkdir(out_session) for f in os.listdir(path): print(f) fn = path + '/' + f if os.path.isdir(fn): od = out_session + '/' + f gen_xshell_session(fn, tpl_file, od) else: if f.startswith('__'): continue ext = f.find('.ini') ip = f[0:ext] xshell_cfg_file = out_session + '/' + ip + '.xsh' ifn = open(tpl_file, 'r') lns = ifn.readlines() ifn.close() tpl = os.path.basename(tpl_file) tpl_n = tpl.find('.xsh') tpl_ip = tpl[0:tpl_n] ofn = open(xshell_cfg_file, 'w') for ln in lns: ln = ln.replace(tpl_ip, ip) ofn.write(ln) ofn.close() if __name__ == '__main__': secrt_session = argv[1] xshell_xsh_tpl_file = argv[2] xshell_out_session_dir = argv[3] gen_xshell_session(secrt_session, xshell_xsh_tpl_file, xshell_out_session_dir)