Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   passing passords to pgsql/pg_create/pg_dump programmatically (http://www.velocityreviews.com/forums/t902217-passing-passords-to-pgsql-pg_create-pg_dump-programmatically.html)

filippo 03-12-2007 05:22 PM

passing passords to pgsql/pg_create/pg_dump programmatically
 
Hello,

I have written a program perl/Tkprogram, based on postgres. For
maintenance reasons in my program I use these commands:

`dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
`pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;

my @psqlOutput = `psql -l -U postgres -h $_`;


my program has a graphic interface but whenever I use these command,
postgres ask for passord in the command line. How can I give these
commands the right passowrd programmatically or how can I interact
with these to give the passwords by a graphic box?

Thanks and best refards,

Filippo


J. Gleixner 03-12-2007 06:01 PM

Re: passing passords to pgsql/pg_create/pg_dump programmatically
 
filippo wrote:
> Hello,
>
> I have written a program perl/Tkprogram, based on postgres. For
> maintenance reasons in my program I use these commands:
>
> `dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
> `createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
> `pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
> U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
>
> my @psqlOutput = `psql -l -U postgres -h $_`;
>
>
> my program has a graphic interface but whenever I use these command,
> postgres ask for passord in the command line. How can I give these
> commands the right passowrd programmatically or how can I interact
> with these to give the passwords by a graphic box?


Read the documentation for those commands to determine how the user
name and/or password is passed, then add the options and values to your
program. Since you wrote the above code, you should be able to figure
out how to add another option and value.

Filippo 03-13-2007 10:11 AM

Re: passing passords to pgsql/pg_create/pg_dump programmatically
 
On 12 Mar, 19:01, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:
> filippo wrote:
> > Hello,


> Read the documentation for those commands to determine how the user
> name and/or password is passed, then add the options and values to your
> program. Since you wrote the above code, you should be able to figure
> out how to add another option and value.


these commands don't accept password command line options, just put on
standard output the string "passord:" and read the standard input for
the value from user. I want to interact with them to pass the
information programmatically (redirect std input/output?).

Thanks,

Filippo


Josef Moellers 03-13-2007 10:16 AM

Re: passing passords to pgsql/pg_create/pg_dump programmatically
 
Filippo wrote:
> On 12 Mar, 19:01, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
>
>>filippo wrote:
>>
>>>Hello,

>
>
>>Read the documentation for those commands to determine how the user
>>name and/or password is passed, then add the options and values to your
>>program. Since you wrote the above code, you should be able to figure
>>out how to add another option and value.

>
>
> these commands don't accept password command line options, just put on
> standard output the string "passord:" and read the standard input for
> the value from user. I want to interact with them to pass the
> information programmatically (redirect std input/output?).


Have a look at Expect. Originally it's Tcl based, but a Perl port also
exists on CPAN.

--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett


Ben Morrow 03-13-2007 10:38 PM

Re: passing passords to pgsql/pg_create/pg_dump programmatically
 
[pgsql.general trimmed: it doesn't exist]

Quoth "filippo" <filippo2991@virgilio.it>:
> Hello,
>
> I have written a program perl/Tkprogram, based on postgres. For
> maintenance reasons in my program I use these commands:
>
> `dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
> `createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
> `pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
> U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
>
> my @psqlOutput = `psql -l -U postgres -h $_`;
>
>
> my program has a graphic interface but whenever I use these command,
> postgres ask for passord in the command line. How can I give these
> commands the right passowrd programmatically or how can I interact
> with these to give the passwords by a graphic box?


Read the manpages for those commands to find the appropriate equivalent
SQL (which exists, in every case: the commands just connect to the DB
and send SQL); then send that using DBI.

Ben

--
Raise your hand if you're invulnerable.
[ben@morrow.me.uk]

Filippo 03-15-2007 08:25 AM

Re: passing passords to pgsql/pg_create/pg_dump programmatically
 
On 13 Mar, 23:38, Ben Morrow <b...@morrow.me.uk> wrote:
> [pgsql.general trimmed: it doesn't exist]
>
> Quoth "filippo" <filippo2...@virgilio.it>:
>
>
>
> > Hello,

>
> > I have written a program perl/Tkprogram, based on postgres. For
> > maintenance reasons in my program I use these commands:

>
> > `dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
> > `createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
> > `pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
> > U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;

>
> > my @psqlOutput = `psql -l -U postgres -h $_`;

>
> > my program has a graphic interface but whenever I use these command,
> > postgres ask for passord in the command line. How can I give these
> > commands the right passowrd programmatically or how can I interact
> > with these to give the passwords by a graphic box?

>
> Read the manpages for those commands to find the appropriate equivalent
> SQL (which exists, in every case: the commands just connect to the DB
> and send SQL); then send that using DBI.


thanks Ben,
the problem for me with this strategy is to re-create this

pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;

it is a dump (sql command) plus a pipe into another SQL command. I
don't figure out how to implement into simple SQL. By the way, thanks
for the hint.

BR,

Filippo




Lars Haugseth 03-20-2007 02:04 PM

Re: passing passords to pgsql/pg_create/pg_dump programmatically
 

* "filippo" <filippo2991@virgilio.it> wrote:
>
> Hello,
>
> I have written a program perl/Tkprogram, based on postgres. For
> maintenance reasons in my program I use these commands:
>
> `dropdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
> `createdb -U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
> `pg_dump -U postgres -h $DATABASE_SERVER $DATABASE_NAME | psql -
> U postgres -h $BACKUP_SERVER $BACKUP_DATABASE_NAME`;
>
> my @psqlOutput = `psql -l -U postgres -h $_`;
>
>
> my program has a graphic interface but whenever I use these command,
> postgres ask for passord in the command line. How can I give these
> commands the right passowrd programmatically or how can I interact
> with these to give the passwords by a graphic box?


$ dropdb --help
$ createdb --help
$ pg_dump --help

As you can see, all of these command line utilities accept the -W
parameter followed by the password.

Alternatively you can configure PostgreSQL to allow connections
from certain clients without password authentication:

http://www.postgresql.org/docs/8.2/s...ntication.html

--
Lars Haugseth

"If anyone disagrees with anything I say, I am quite prepared not only to
retract it, but also to deny under oath that I ever said it." -Tom Lehrer


All times are GMT. The time now is 12:11 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.