Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编辑MongoDB配置文件的Bash脚本_Mongodb_Bash_Shell_Ubuntu 16.04 - Fatal编程技术网

编辑MongoDB配置文件的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

我想在安装时使用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

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