SHELL 中直接替换 template 中变量方法

目标:

分别定义 parameter  template 文件
利用 shell 直接一次性替换 template 中变量

parameter 文件

cephuuid=c45b752d-5d4d-4d3a-a3b2-04e73eff4ccd
cephmonhost=hh-ceph-128040,hh-ceph-128214,hh-ceph-128215
cephmonipaddr=10.199.128.40,10.199.128.214,10.199.128.215
cephmonnetwork=10.199.128.0/22
cephdatanetwork=240.30.128.0/21
cePHPgnum=1024
cePHPgpnum=1024

template 文件

[global]
fsid = $cephuuid
mon initial members = $cephmonhost
mon host = $cephmonipaddr
public network = $cephmonnetwork
cluster network = $cephdatanetwork
auth cluster required = cephx
auth service required = cephx
auth client required = cephx
osd journal size = 2048
filestore xattr use omap = true
osd pool default size = 3
osd pool default min size = 1
osd pool default pg num = $cePHPgnum
osd pool default pgp num = $cePHPgpnum
osd crush chooseleaf type = 1

执行方法

#!/bin/bash
source parameter

eval "cat <<EOF $(<ceph.conf.template) EOF " 2> /dev/null

结果

[root@hh-ceph-128040 ceph]# . gen_ceph_conf.sh
[global]
fsid = c45b752d-5d4d-4d3a-a3b2-04e73eff4ccd
mon initial members = hh-ceph-128040,hh-ceph-128215
mon host = 10.199.128.40,10.199.128.214,10.199.128.215
public network = 10.199.128.0/22
cluster network = 240.30.128.0/21
auth cluster required = cephx
auth service required = cephx
auth client required = cephx
osd journal size = 2048
filestore xattr use omap = true
osd pool default size = 3
osd pool default min size = 1
osd pool default pg num = 1024
osd pool default pgp num = 1024
osd crush chooseleaf type = 1

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...