shell中更新多个配置文件

有三个配置文件conf1.properties、conf2.properties、conf3.properties,和一个标准文件right.properties。标准文件中的内容为三个配置文件中所有的配置项及标准值。
三个配置文件在/home/conf目录下,标准文件在/home下.
conf1.properties>>>>>>>>>>
user.name=zhangsan
user.number=123456
...


conf2.properties>>>>>>>>>>
service.IP=127.0.0.1
user.job=SE
...


conf3.properties>>>>>>>>>>
woker.hobby=soccer
woker.selary=2000
...
right.properties>>>>>>>>>>
name=zhangsan
number=123456
...
IP=127.0.0.1
job=SE
...
hobby=soccer
selary=2000
...


要求:运行test脚本,将三个文件中的配置项的值改为标准配置文件中对应配置项的值。
#!/bin/bash
current_dir='/home'
CONF_DIR=${current_dir}/conf
Install_Param_file=${current_dir}/right.properties
##批量修改linux文件格式
sudo find ${current_dir}/conf -name "*.properties" | xargs dos2unix  -q
sudo find ${current_dir} -name "*.properties" | xargs dos2unix -q
sudo find ${current_dir} -name "*.sh" | xargs dos2unix -q


LOCAL_IP=$(ifconfig eth0|grep -w inet | awk -F: '{print $2}' | awk '{print $1}')
HOST_NAME=$(hostname)








##根据参数获取配置参数并配置参数
function getParameter()
{
   Par=$(cat ${Install_Param_file} | grep "^$1" |awk -F '=' '{print $2}')
   sed -i "s#$1=.*#$1=$Par#g" $2
}








##修改一些配置
function updateVODConfig()
{
        getParameter user.name ${CONF_DIR}/mongo.properties


        getParameter user.number ${CONF_DIR}/service.properties
        getParameter service.IP ${CONF_DIR}/service.properties


        getParameter user.job ${CONF_DIR}/service.properties
        getParameter woker.hobby ${CONF_DIR}/service.properties
        getParameter woker.selary ${CONF_DIR}/service.properties
}


function main()
{
        echo ${LOCAL_IP}
        echo ${HOST_NAME}


        updateVODConfig
}


main
echo "update successfully"


exit 0
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值