4

I am trying to install postgresql and generate a random password for it on deployment, just for testing. Something like this:

$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'"

The error I get back is this:

=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 ''

Can anyone please explain why this is happening?

0

1 Answer 1

6

Your first line needs to be altered (variables assignments should not have a dollar sign):

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

The error also suggests that $PROJECT is not being set - what do you get if you add echo "$PROJECT - $DBPASS" after the first line?

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. The second error was because I hadn't set $project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.