跟新多个配置文件

有三个配置文件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

猜你喜欢

转载自blog.csdn.net/gramdog/article/details/80334143