Create a new postgres user programmatically, without interactive intervention
You can do that using plain SQL after connecting as a superuser (e.g. postgres
) to the database in question:
create user user1 password 'foobar'
If you need to do this from within a script you can put that into a sql file and then pass this to psql:
ยป sudo -u postgres psql --file=create_user.sql
From the shell, you could use an here-document, like:
#!/bin/shpsql -U postgres postgres <<OMG CREATE USER lutser password '`cat /tmp/xxx`' ;OMG
BTW: I'don't think it is a good idea to store the password in /tmp/
, not even temporally.