How to check configuration options in httpd.conf

I need to write python code for:

  • Read a text file as input (separated by tabs and usually two columns)
  • Check the httpd.conf file for this setting and its meaning

For example, I have a text file:

KeepAlive  on
Listen     80
TCP        On

      

and a normal file httpd.conf

.

I want to check and compare the fields of each line and if the configuration was correct then print keepalive is ok

eg.

I wrote this:

d = []
with open("config.txt") as CFGF:
    for line in CFGF:
        key, val = line.split()
        c = key, val
        d.extend(c)

with open("httpd.conf") as f:
    j = 0
    for i in d:
        for line in f:
            ls = line.strip()
            if d[j] in line:
                if d[j + 1] in line:
                    print(line.rsplit())
        j += 1

      

+3


source to share


1 answer


Finally, I wrote something that works (below), but one thing remains (match exact words and ignore cases).



l = []
with open('config.txt') as cfg:
    for line in cfg:
        l.extend(line.split())
a, b = zip(*(s.split("~") for s in l))
for w in range(len(a)):
    with open('httpd.conf') as apache:
        for lines in apache:
            if (a[w]) in lines and not lines.startswith("#") and not lines.__contains__("#"):
                if (b[w]) in lines:
                    print(lines.rstrip())

      

0


source







All Articles