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

前端之家收集整理的这篇文章主要介绍了SHELL 中直接替换 template 中变量方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

目标:

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

parameter 文件

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

template 文件

  1. [global]
  2. fsid = $cephuuid
  3. mon initial members = $cephmonhost
  4. mon host = $cephmonipaddr
  5. public network = $cephmonnetwork
  6. cluster network = $cephdatanetwork
  7. auth cluster required = cephx
  8. auth service required = cephx
  9. auth client required = cephx
  10. osd journal size = 2048
  11. filestore xattr use omap = true
  12. osd pool default size = 3
  13. osd pool default min size = 1
  14. osd pool default pg num = $cePHPgnum
  15. osd pool default pgp num = $cePHPgpnum
  16. osd crush chooseleaf type = 1

执行方法

  1. #!/bin/bash
  2. source parameter
  3.  
  4. eval "cat <<EOF $(<ceph.conf.template) EOF " 2> /dev/null

结果

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

猜你在找的Bash相关文章