我有一个bash部署脚本(linode stackscript),它在部署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运行它时,它运行的是postgres行,但之后什么也不运行。
其次,当我运行postgres行时,它要求我手动输入密码。有没有办法将它作为变量放入there脚本中?
发布于 2012-12-06 15:49:15
passwd是用来交互使用的。在批处理中更改密码的正确命令是chpasswd。
示例:
#!/bin/sh
echo 'postgres:newpassword' | chpasswd还要注意的是,您的脚本所做的su - postgres看起来并不像通常在非交互模式下完成的。最好做:su -c 'command1; command2...' - postgres
https://stackoverflow.com/questions/13732240
复制相似问题