Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.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
PostgreSQL部署脚本暂停_Sql_Bash_Postgresql_Shell_Debian - Fatal编程技术网

PostgreSQL部署脚本暂停

PostgreSQL部署脚本暂停,sql,bash,postgresql,shell,debian,Sql,Bash,Postgresql,Shell,Debian,我有一个bashshell部署脚本(linodestackscript),它在部署Debian6.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

我有一个bashshell部署脚本(linodestackscript),它在部署Debian6.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行时,它要求我手动输入密码。有什么方法可以将它作为一个变量放入shell脚本中吗?

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

例如:

#!/bin/sh
echo 'postgres:newpassword' | chpasswd
还要注意的是,您的脚本执行su-postgres的方式看起来不像是在非交互模式下执行的。 最好这样做:
su-c'command1;命令2…'-postgres