config 写入
d代码:
# __author__ = liukun
# coding:utf-8
line = input("please input the config \n :")
#提示输入字符
#输入{"backend":"www.oldboy.org","record":{"server":"100.1.70.9","weight":20,"maxconm":3000}}
a_dict = eval(line)#转换为字典
dict_b = a_dict['record']
line_b = a_dict['backend']
file_Read = open("config")#打开配置文件
file_Write = open("config.bak", 'w')#打开临时文件
file_test = file_Read.readline()#按行读取配置文件
while ('' != file_test):
line = file_test.split()
if line.count('backend') == 1 and line.count(a_dict['backend']) == 1 : #匹配域名所在行
file_Write.write('\n' + file_test)
string = "server %s weight %s maxconn %s" %(dict_b['server'], dict_b['weight'],dict_b['maxconm'])
#写入值太长,先用变量格式化.
file_Write.write('\t'*2 + string + '\n')#添加 两个tab保持缩进对齐,末尾换行
file_test = file_Read.readline()
else:
file_Write.write(file_test)
file_test = file_Read.readline()
file_Read.close()
file_Write.close()#遍历完毕,关闭文件
file_Read_2 = open("config.bak") #将 bak 文件内容回写源文件 config
file_Write_2 = open("config", 'w')
file_test_2 = file_Read_2.readline()
while ('' != file_test_2):
file_Write_2.write(file_test_2)
file_test_2 = file_Read_2.readline()
file_Read_2.close()
file_Write_2.close()
config:
global
log 127.0.0.1 local2
daemon
maxconn 256
log 127.0.0.1 local2 info
defaults
log global
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
option dontlognull listen stats :8888
stats enable
stats uri /admin
stats auth admin:1234 frontend oldboy.org
bind 0.0.0.0:80
option httplog
option httpclose
option forwardfor
log global
acl www hdr_reg(host) -i www.oldboy.org
use_backend www.oldboy.org if www backend www.oldboy.org
server 100.1.70.9 weight 20 maxconn 31111
server 100.1.70.9 weight 20 maxconn 3000
server 100.1.70.9 weight 20 maxconn 3000
server 100.1.70.9 weight 20 maxconn 344444
server 100.1.70.9 weight 20 maxconn 3000
server 100.1.70.9 weight 20 maxconn 3000
server 100.1.7.9 100.1.7.9 weight 20 maxconn 3000

config 写入的更多相关文章
- python向config、ini文件读取写入
config读取操作 cf = configparser.ConfigParser() # 实例化对象 cf.read(filename) # 读取文件 cf.sections() # 读取secti ...
- C# 程序修改config文件后,不重启程序刷新配置ConfigurationManager
基本共识: ConfigurationManager 自带缓存,且不支持 写入. 如果 通过 文本写入方式 修改 配置文件,程序 无法刷新加载 最新配置. PS. Web.config 除外:Web. ...
- 配置Jenkins使用Gitlab的代码库进行构建
1. 首先确认Jenkins上安装了Git plugin, 以及Subversion plugin Manage Jenkins -> Plugin Manager -> Availabl ...
- ZooKeeper的Znode剖析
在ZooKeeper中,节点也称为znode.由于对于程序员来说,对zk的操作主要是对znode的操作,因此,有必要对znode进行深入的了解. ZooKeeper采用了类似文件系统的的数据模型,其节 ...
- ubuntu下ssh使用proxy:corkscrew
1,安装corkscrew: sudo apt-get install corkscrew 2, 配置 vim ~/.ssh/config 写入如下: Host 10.1.*.* ProxyComma ...
- 『随笔』C# 程序 修改 ConfigurationManager 后,不重启 刷新配置
基本共识: ConfigurationManager 自带缓存,且不支持 写入. 如果 通过 文本写入方式 修改 配置文件,程序 无法刷新加载 最新配置. PS. Web.config 除外:Web. ...
- node.js NPM 使用
n=NPM是一个Node包管理和分发工具,已经成为了非官方的发布Node模块(包)的标准.有了NPM,可以很快的找到特定服务要使用的包,进行下载.安装以及管理已经安装的包.npms安装: 下载npm源 ...
- 黑苹果引导工具 Clover 配置详解及Clover Configurator使用
黑苹果引导工具 Clover 配置详解及Clover Configurator使用 2017-03-11 14:01:40 by SemiconductorKING 转自:@三个表哥 简介: 可 ...
- CentOS6.9下安装rabbitmq消息队列
安装如下步骤: 首先安装erlang yum install erlang 安装rabbitmq rpm包 wget http://www.rabbitmq.com/releases/rabbitmq ...
随机推荐
- POJ 1066 Treasure Hunt --几何,线段相交
题意: 正方形的房子,给一些墙,墙在区域内是封闭的,给你人的坐标,每穿过一道墙需要一把钥匙,问走出正方形需要多少把钥匙. 解法: 因为墙是封闭的,所以绕路也不会减少通过的墙的个数,还不如不绕路走直线, ...
- HDU 5044 Tree --树链剖分
题意:给一棵树,两种操作: ADD1: 给u-v路径上所有点加上值k, ADD2:给u-v路径上所有边加上k,初始值都为0,问最后每个点和每条边的值,输出. 解法:树链剖分可做,剖出来如果直接用线段树 ...
- POJ 1703 Find them,Catch them ----种类并查集(经典)
http://blog.csdn.net/freezhanacmore/article/details/8774033?reload 这篇讲解非常好,我也是受这篇文章的启发才做出来的. 代码: #i ...
- Java Executor并发框架(二)剖析ThreadPoolExecutor运行过程
上一篇从整体上介绍了Executor接口,从上一篇我们知道了Executor框架的最顶层实现是ThreadPoolExecutor类,Executors工厂类中提供的newScheduledThrea ...
- Android View坐标getLeft, getRight, getTop, getBottom
1 引起疑惑 分析视图invalidate流程的过程中发现view的left, right, top, bottom跟自己理解的不一样,现在想分析一下这几个值具体的含义. 2 理解坐标,位置概念 ...
- [4]Telerik Grid 简单使用方法
1.columns <% Html.Telerik().Grid(Model) .Name("Orders") .Columns(columns => { //绑定列名 ...
- Linux 网络编程八(epoll应用--大并发处理)
//头文件 pub.h #ifndef _vsucess #define _vsucess #ifdef __cplusplus extern "C" { #endif //服务器 ...
- U3D assetbundle加载
using UnityEngine; using System.Collections; public class testLoadFromAB : MonoBehaviour { IEnumerat ...
- Eclipse下配置tomcat且使用eclipse开启debug模式,集成JAD反编译插件
Eclipse运行Tomcat的2种方式 eclipse启动Tomcat服务输入http://localhost:8080/报404解决方法 Eclipse 中Tomcat 启动 与直接启动Tomca ...
- [iOS翻译]《iOS7 by Tutorials》系列:iOS7的设计精髓(上)
简介: 本文翻译自<iOS7 by Tutorials>一书的第一章“Designing for iOS 7”,主要从程序员角度介绍了iOS7的新设计理念,堪称神作!本文翻译仅作学习交流之 ...