【发布时间】:2017-04-06 16:16:12
【问题描述】:
我正在尝试通过配置脚本在 ubuntu/vagrant 上设置 postgres 9.6。我的部分脚本使用以下命令向pg_hba.conf 添加了一行:
sudo -u postgres echo "host all all all md5" >> /etc/postgresql/9.6/main/pg_hba.conf
但是,这给了我错误-bash: /etc/postgresql/9.6/main/pg_hba.conf: Permission denied
这很奇怪,因为我可以使用sudo nano 或sudo -u postgres nano 编辑文件。
以下是文件的权限:
-rw-r----- 1 postgres postgres 4641 Apr 6 16:11 pg_hba.conf
如何在脚本中将此行添加到我的配置文件中?
【问题讨论】:
-
您的
sudo覆盖echo,而不是>>。如果你引用整个事情,它应该会更好。 -
echo "host..." | sudo tee -a filename工作吗? -
@MikeSherrill'CatRecall' 似乎有效。你会添加一个答案,以便我可以信任你吗?
标签: bash postgresql ubuntu unix vagrant