Jump to content

[PY]Config proxy ip in CONFIG Files /w backup mechanism


Recommended Posts

  • Premium

import os

#no of channels
channels = 4

#no of cores
cores = 2

#Channels path
chan_location = "/usr/home/main/srv1/chan/"

#New ip to replace the old
ip_value = "123.443.9.1"

try:
    os.mkdir("%sbackup_config" % chan_location)
except Exception:
    pass

for i in range(1, channels + 1):
    # print(i)
    for core in range(1, cores + 1):
        with open(f"%sch{i}/core{core}/CONFIG" % chan_location, 'r') as cfg:
            count = 0
            proxy_index = 0
            list_of_lines = cfg.readlines()
            with open(f"%sbackup_config/config_channel{i}_core{core}" % chan_location, "w") as bk_file:
                bk_file.writelines(list_of_lines)

            for line in list_of_lines:
                count += 1
                # print(line)
                if "proxy" in line.lower():
                    proxy_index = count - 1
            # print(len(list_of_lines), 'list of lines len')
            print("proxy index ", proxy_index)
            list_of_lines[proxy_index] = "proxy_ip: %s\n" % ip_value
        with open(f"%sch{i}/core{core}/CONFIG" % chan_location, 'w') as cfg_w:
            cfg_w.writelines(list_of_lines)
            print(f"Succesfully updated config for Channel{i}, Core{core}")

 

  • Good 2
  • Love 1
  • Love 1
Link to comment
Share on other sites

3 hours ago, astroNOT said:

import os

#no of channels
channels = 4

#no of cores
cores = 2

#Channels path
chan_location = "/usr/home/main/srv1/chan/"

#New ip to replace the old
ip_value = "123.443.9.1"

try:
    os.mkdir("%sbackup_config" % chan_location)
except Exception:
    pass

for i in range(1, channels + 1):
    # print(i)
    for core in range(1, cores + 1):
        with open(f"%sch{i}/core{core}/CONFIG" % chan_location, 'r') as cfg:
            count = 0
            proxy_index = 0
            list_of_lines = cfg.readlines()
            with open(f"%sbackup_config/config_channel{i}_core{core}" % chan_location, "w") as bk_file:
                bk_file.writelines(list_of_lines)

            for line in list_of_lines:
                count += 1
                # print(line)
                if "proxy" in line.lower():
                    proxy_index = count - 1
            # print(len(list_of_lines), 'list of lines len')
            print("proxy index ", proxy_index)
            list_of_lines[proxy_index] = "proxy_ip: %s\n" % ip_value
        with open(f"%sch{i}/core{core}/CONFIG" % chan_location, 'w') as cfg_w:
            cfg_w.writelines(list_of_lines)
            print(f"Succesfully updated config for Channel{i}, Core{core}")

 

can u explain more what is that

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.