#!/usr/bin/env python # coding=utf-8 # nohup curl -s https://internal.up-gram.com/shell/update.xml_public_ip.py |python xxxx >/dev/null 2>&1 & from xml.etree.ElementTree import ElementTree, Element import shlex import sys def bash(cmd): ''' 执行执行bash命令 ''' return shlex.os.system(cmd) def read_string(content): root = ElementTree.fromstring(content) def read_xml(in_path): ''' 读取并解析xml文件 in_path: xml路径 return: ElementTree ''' tree = ElementTree() tree.parse(in_path) return tree def write_xml(tree, out_path): ''' 将xml文件写出 tree: xml树 out_path: 写出路径 ''' tree.write(out_path, encoding="utf-8") def ipv6_config(): # listen_ip =server['listen_ip'] # server['listen_ip'] = '{0}|{1}'.format(listen_ip,ipv6) public_ip = server['public_ip'] if '|' in public_ip: public_ip_list = public_ip.split('|') server['public_ip'] = '#'.join(public_ip_list) print(public_ip_list) if __name__ == '__main__': # ipv6 = sys.argv[1] tree = read_xml('/etc/dingtone/xedge-config.xml') root = tree.getroot() server = root.find('server').attrib # ipv6_config(ipv6) ipv6_config() write_xml(tree,'/etc/dingtone/xedge-config.xml') # 写入配置 print(server) bash("sed -i 's/ldSkyVPN-WebServer-995438515.us-west-1.elb.amazonaws.com/webserver.skyvpnapi.com/g' /etc/dingtone/xedge-config.xml") bash('/root/restartvpn.sh')