Bash脚本来编辑MongoDB配置文件

时间:2018-10-15 05:56:53

标签: mongodb bash shell ubuntu-16.04

我想在安装时使用bash脚本将bindIp:127.0.0.0替换为bindIP:0.0.0.0。 有人可以告诉我如何通过bash做到这一点吗?

要编辑的部分:

    # network interfaces
 net:
  port: 27017
  bindIp: 127.0.0.0

127.0.0.0替换为0.0.0.0

我正在使用的命令:

sed '0,/bindIp:*;/s//bindIp: 0.0.0.0;/' /etc/mongod.conf

1 个答案:

答案 0 :(得分:0)

Target System (x86)
Subtarget (x86_64)
Target Profile (Generic)

如果您想即时编辑文件,请使用选项sed "s,\\(^[[:blank:]]*bindIp:\\) .*,\\1 0.0.0.0," /etc/mongod.conf

-i
相关问题