pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedpsql and password
3+ messages / 2 participants
[nested] [flat]
* psql and password
@ 2002-03-28 01:47 Rudi Starcevic <rudi@oasis.net.au>
2002-03-28 05:06 ` Re: psql and password Rudi Starcevic <rudi@oasis.net.au>
2002-03-28 07:11 ` Re: psql and password Oliver Elphick <olly@lfix.co.uk>
0 siblings, 2 replies; 3+ messages in thread
From: Rudi Starcevic @ 2002-03-28 01:47 UTC (permalink / raw)
To: pgsql-sql
Hi,
I'm wondering how I can create a database for a user from within a script.
I have Pg in 'password' mode.
To create this database I'm trying to pass in the password from the script.
For example :
echo myPgPassword | /usr/local/pgslq/bin/createdb yourNewPgDatabase
But it's not working.
I'm still prompted for the password.
My goal is to create the database then change ownership of the database.
The user can then log straight in using phpPgAdmin.
Can you see where I'm going wrong ?
Any suggestions ?
Perhaps I need to use 'Expect' or something ( this is a Debian box )
Thanks
Kind Regards
Rudi.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: psql and password
2002-03-28 01:47 psql and password Rudi Starcevic <rudi@oasis.net.au>
@ 2002-03-28 05:06 ` Rudi Starcevic <rudi@oasis.net.au>
1 sibling, 0 replies; 3+ messages in thread
From: Rudi Starcevic @ 2002-03-28 05:06 UTC (permalink / raw)
To: pgsql-sql
Hi,
Thanks for the suggestions,
I ended up using Perl and DBI.
First I create a new database,
then create a new user,
then change owership of the database to the new user,
then create and entry for Apache's htpasswd facility.
Then the new user logs into the new database with there new htpasswd
account via phpPgAdmin.
Thanks again.
For those interested here's my script.
Cheers
Rudi.
Script :
#!/usr/bin/perl -w
use DBI;
$DBH = DBI ->connect("dbi:Pg:dbname=oasis;host=moon","postgres","rudi2000");
foreach $_ (@ARGV)
{
# get name and pwd
@data = split(/:/,$_);
$thisname = $data[0];
$thispwd = $data[1];
# create a new user
$sql = $DBH->prepare("CREATE USER $thisname WITH PASSWORD '$thispwd'
NOCREATEDB NOCREATEUSER;");
$sql->execute();
# create a new database
$sql = $DBH->prepare("CREATE DATABASE $thisname WITH
TEMPLATE=template0;");
$sql->execute();
# change database ownership
$sql = $DBH->prepare("UPDATE pg_database SET datdba = (SELECT
usesysid FROM pg_shadow WHERE usename = '$thisname') WHERE datname =
'$thisname';");
$sql->execute();
# create htpaswd account
system("/usr/local/apache/bin/htpasswd -b /home/realmz/phpPgAdmin
$thisname $thispwd >> /root/scripts/htpasswd_log.txt 2>&1");
}
$DBH->disconnect;
Rudi Starcevic wrote:
> Hi,
>
> I'm wondering how I can create a database for a user from within a
> script.
> I have Pg in 'password' mode.
> To create this database I'm trying to pass in the password from the
> script.
> For example :
>
> echo myPgPassword | /usr/local/pgslq/bin/createdb yourNewPgDatabase
>
> But it's not working.
> I'm still prompted for the password.
>
> My goal is to create the database then change ownership of the database.
> The user can then log straight in using phpPgAdmin.
>
> Can you see where I'm going wrong ?
> Any suggestions ?
> Perhaps I need to use 'Expect' or something ( this is a Debian box )
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: psql and password
2002-03-28 01:47 psql and password Rudi Starcevic <rudi@oasis.net.au>
@ 2002-03-28 07:11 ` Oliver Elphick <olly@lfix.co.uk>
1 sibling, 0 replies; 3+ messages in thread
From: Oliver Elphick @ 2002-03-28 07:11 UTC (permalink / raw)
To: Rudi Starcevic <rudi@oasis.net.au>; +Cc: pgsql-sql
On Thu, 2002-03-28 at 01:47, Rudi Starcevic wrote:
> To create this database I'm trying to pass in the password from the script.
> For example :
>
> echo myPgPassword | /usr/local/pgslq/bin/createdb yourNewPgDatabase
Set the environment variable:
PGPASSWORD=myPgPassword /usr/local/pgslq/bin/createdb yourNewPgDatabase
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
"Thou wilt keep him in perfect peace, whose mind is
stayed on thee; because he trusteth in thee."
Isaiah 26:3,4
Attachments:
signature.asc (application/pgp-signature, 231B) download
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2002-03-28 07:11 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-03-28 01:47 psql and password Rudi Starcevic <rudi@oasis.net.au>
2002-03-28 05:06 ` Rudi Starcevic <rudi@oasis.net.au>
2002-03-28 07:11 ` Oliver Elphick <olly@lfix.co.uk>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox