passing passords to pgsql/pg_create/pg_dump programmatically

Discussion in 'Perl Misc' started by filippo, Mar 12, 2007.

  1. filippo

    filippo Guest

    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
    filippo, Mar 12, 2007
    #1
    1. Advertising

  2. filippo

    J. Gleixner Guest

    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.
    J. Gleixner, Mar 12, 2007
    #2
    1. Advertising

  3. filippo

    Filippo Guest

    On 12 Mar, 19:01, "J. Gleixner" <>
    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
    Filippo, Mar 13, 2007
    #3
  4. Filippo wrote:
    > On 12 Mar, 19:01, "J. Gleixner" <>
    > 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
    Josef Moellers, Mar 13, 2007
    #4
  5. filippo

    Ben Morrow Guest

    [pgsql.general trimmed: it doesn't exist]

    Quoth "filippo" <>:
    > 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, Mar 13, 2007
    #5
  6. filippo

    Filippo Guest

    On 13 Mar, 23:38, Ben Morrow <> wrote:
    > [pgsql.general trimmed: it doesn't exist]
    >
    > Quoth "filippo" <>:
    >
    >
    >
    > > 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
    Filippo, Mar 15, 2007
    #6
  7. * "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?


    $ 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/static/client-authentication.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
    Lars Haugseth, Mar 20, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TB
    Replies:
    0
    Views:
    407
  2. Victor Bazarov
    Replies:
    25
    Views:
    844
    E. Robert Tisdale
    Mar 23, 2005
  3. Gerardo Herzig -Departamento de Proyectos Especial

    cPickle and pgsql...damn!!

    Gerardo Herzig -Departamento de Proyectos Especial, Jul 20, 2004, in forum: Python
    Replies:
    3
    Views:
    301
    Gerardo Herzig -Departamento de Proyectos Especial
    Jul 21, 2004
  4. pereges
    Replies:
    7
    Views:
    421
    pereges
    Jun 1, 2008
  5. Filippo
    Replies:
    1
    Views:
    100
    Filippo
    Apr 8, 2007
Loading...

Share This Page