编辑MongoDB配置文件的Bash脚本
我想在安装时使用bash脚本将bindIp:127.0.0.0替换为bindIp:0.0.0。 有人能告诉我如何通过bash实现这一点吗 要编辑的部分:编辑MongoDB配置文件的Bash脚本,mongodb,bash,shell,ubuntu-16.04,Mongodb,Bash,Shell,Ubuntu 16.04,我想在安装时使用bash脚本将bindIp:127.0.0.0替换为bindIp: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 如果要动态编辑文件,请使用选项-i
# 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
如果要动态编辑文件,请使用选项-i
sed -i "s,\\(^[[:blank:]]*bindIp:\\) .*,\\1 0.0.0.0," /etc/mongod.conf
我收到错误:“sed:无法打开临时文件/etc/sedm01lM0:权限被拒绝”这是因为您不是root用户,而不是因为
sed
命令有任何问题。。。。或者您可能在Docker内部,Docker有时在某些系统位置表现得非常怪异。使用单引号而不是双引号可以将双反斜杠更改为单引号。@rahuland是的,正如@tripleee所解释的,您可能需要sudo
来运行此命令<代码>sudo sed-i“s,\\(^[:blank:]*bindIp:\\).*,\\1 0.0.0,“/etc/mongod.conf。
sed -i "s,\\(^[[:blank:]]*bindIp:\\) .*,\\1 0.0.0.0," /etc/mongod.conf