gpt4 book ai didi

linux - 在 bash 中为 postgresql 生成随 secret 码

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:54:34 26 4
gpt4 key购买 nike

我正在尝试安装 postgresql 并在部署时为其生成一个随 secret 码,仅用于测试。像这样:

$DBPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
sudo -u postgres -H createuser --no-createrole --no-superuser --no-createdb $NAME
sudo -u postgres -H createdb -O $PROJECT $PROJECT
sudo -u postgres -H psql -c "alter user $PROJECT with password '$DBPASS'"

我得到的错误是这样的:

=b3wDxlSbUymho0CmOZ4TgPylLCanKdgJ: command not found /usr/lib/postgresql/9.1/bin/createdb: option requires an argument -- 'O' Try "createdb --help" for more information.
ERROR: syntax error at or near "with password"
LINE 1: alter user with password ''

谁能解释一下为什么会这样?

最佳答案

您的第一行需要更改(变量分配不应有美元符号):

DBPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)

该错误还表明未设置 $PROJECT - 如果在第一行之后添加 echo "$PROJECT - $DBPASS" 会得到什么?

关于linux - 在 bash 中为 postgresql 生成随 secret 码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22379465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com