【问题标题】:PostgreSQL Deployment Script StallsPostgreSQL 部署脚本停止
【发布时间】:2012-12-05 20:54:52
【问题描述】:

我有一个 bash shell 部署脚本(linode stackscript),它在我部署我的 debian 6.0 服务器时运行。脚本以root身份运行,脚本如下:

apt-get update
apt-get install postgresql postgresql-contrib pgadmin3

passwd postgres
su - postgres
psql -c "ALTER USER postgres WITH PASSWORD 'changeme'" -d template1
su - postgres
createdb mytestdb
psql mytestdb

我有两个问题:

首先,当我通过 shell 手动运行每一行时,它可以工作,但是当我将它作为 stackscript 运行时,它会运行 passwd postgres 行,但之后什么都没有。

其次,当我运行 passwd postgres 行时,它会要求我手动输入密码。有什么办法可以把它作为一个变量放入 shellscript 中?

【问题讨论】:

    标签: sql bash postgresql shell debian


    【解决方案1】:

    passwd 旨在以交互方式使用。 批量修改密码的正确命令是chpasswd

    例子:

    #!/bin/sh
    echo 'postgres:newpassword' | chpasswd
    

    另请注意,您的脚本su - postgres 的执行方式看起来不像通常在非交互模式下执行的那样。 最好这样做:su -c 'command1; command2...' - postgres

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-17
      • 1970-01-01
      • 2018-06-20
      • 2021-05-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多