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

前端之家收集整理的这篇文章主要介绍了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
原文链接:https://www.f2er.com/bash/389646.html

猜你在找的Bash相关文章