Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This is my deployment snippet:

APP="test"
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 $APP_main
sudo -u postgres -H createdb -O $APP_main $APP_main
sudo -u postgres -H psql -c "alter user $APP_main with password '$DBPASS'"

This is my log out:

/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 'hCGCly4ZVfu42Dr956ncypuf6mt0lBiY'

Can anyone explain what is going wrong? I have specified the O argument it just doesn't seem to accept it.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The problem is in:

$APP_main

You perhaps wanted to append _main to the variable $APP. Instead say:

${APP}_main

This would expand the variable $APP and append _main to it.

share|improve this answer
    
What happen if the user already exist? How can I check this? –  Rob3 Mar 18 at 14:35
    
@Rob3 That's a purely database question. I'd say that you ask that in a different thread! –  devnull Mar 18 at 14:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.