前言
整理NG配置文件,每次都去服务器上面去查,很不方便,有时候因为网络限制根本登录不到服务器。于是,就想把服务器的NG配置文件拷贝到本地,集中整理为一张表,就看这张表查各个系统的具体配置。
脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| import os import re import xlwt
book = xlwt.Workbook(encoding='GBK',style_compression=0) sheet = book.add_sheet('XX', cell_overwrite_ok=True) sheet.write(0, 0, '所属NG') sheet.write(0, 1, '配置文件名称') sheet.write(0, 2, '配置文件内容')
path = r"D:\XX-conf" files= os.listdir(path)
a=1 q=1 for file in files: if not os.path.isdir(file): fd = open(path+"/"+file); lines = fd.readlines() string = "" for line in lines: string += line sheet.write(a, 0, 'XX') sheet.write(a, 2, string) a = a+1 sheet.write(q,1,file) q=q+1 book.save('XX-conf.xls')
|
效果