Hi,

I hope, that this is not too off topic for this list, but anyway, it 
should be easy for any PG-expert.

I need to run a shell script that logs in to Postgresql, executes a 
query and logs off again.

In MySQL, I did it like this:

'mysql -u user -ppassword < script.sh'

My problem is that I can't find a way to put the password in an 'psql' 
statement at the prompt.

Any suggestions are welcome!

mfg
ALEX

-- 
________________________________________________________

Institut fuer Geographie und Regionalforschung
Universitï¿½t Wien
Kartografie und Geoinformation

Departement of Geography and Regional Research
University of Vienna
Cartographie and GIS

Universitaetstr. 7, A-1010 Wien, AUSTRIA

Tel: (+43 1) 4277 48644
Fax: (+43 1) 4277 48649
E-mail: pucher@atlas.gis.univie.ac.at

FTP: ftp://ftp.gis.univie.ac.at
WWW: http://www.gis.univie.ac.at/karto
________________________________________________________

"He that will not apply new remedies must expect new evils; for time is the greatest innovator"--Francis Bacon

             



Thu, 10 Jan 2002 09:07:50 +0100
Alexander Pucher <pucher@atlas.gis.univie.ac.at>
Postgres in bash-mode
I used to be able to do:

(echo "login\npassword\n"; bench.sh) | psql -h system database

Don't really know if it works anymore though.  Started using SSL
related tools.

--
Rod Taylor

This message represents the official view of the voices in my head

----- Original Message -----
From: "Alexander Pucher" <pucher@atlas.gis.univie.ac.at>
To: "pgsql-hackers" <pgsql-hackers@postgresql.org>
Sent: Thursday, January 10, 2002 3:07 AM
Subject: [HACKERS] Postgres in bash-mode


> Hi,
>
> I hope, that this is not too off topic for this list, but anyway, it
> should be easy for any PG-expert.
>
> I need to run a shell script that logs in to Postgresql, executes a
> query and logs off again.
>
> In MySQL, I did it like this:
>
> 'mysql -u user -ppassword < script.sh'
>
> My problem is that I can't find a way to put the password in an
'psql'
> statement at the prompt.
>
> Any suggestions are welcome!
>
> mfg
> ALEX
>
> --
> ________________________________________________________
>
> Institut fuer Geographie und Regionalforschung
> Universitï¿½t Wien
> Kartografie und Geoinformation
>
> Departement of Geography and Regional Research
> University of Vienna
> Cartographie and GIS
>
> Universitaetstr. 7, A-1010 Wien, AUSTRIA
>
> Tel: (+43 1) 4277 48644
> Fax: (+43 1) 4277 48649
> E-mail: pucher@atlas.gis.univie.ac.at
>
> FTP: ftp://ftp.gis.univie.ac.at
> WWW: http://www.gis.univie.ac.at/karto
> ________________________________________________________
>
> "He that will not apply new remedies must expect new evils; for time
is the greatest innovator"--Francis Bacon
>
>
>
>
>
> ---------------------------(end of
broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>


Thu, 10 Jan 2002 23:31:23 -0500
"Rod Taylor" <rbt@barchord.com>
Re: Postgres in bash-mode
Alexander Pucher writes:

> In MySQL, I did it like this:
>
> 'mysql -u user -ppassword < script.sh'

Then you might as well not have any authentication at all, because every
user on your system can then read the password off the "ps" output.

> My problem is that I can't find a way to put the password in an 'psql'
> statement at the prompt.

You can put it into the environment variable PGPASSWORD, but that *might*
suffer from the same problems depending on your OS.  If you want real
noninteractive login you will have to use a different authentication
method, such as ident.

-- 
Peter Eisentraut   peter_e@gmx.net


Thu, 10 Jan 2002 23:43:41 -0500 (EST)
Peter Eisentraut <peter_e@gmx.net>
Re: Postgres in bash-mode
On Thu, Jan 10, 2002 at 09:07:50AM +0100, Alexander Pucher wrote:
> Hi,
> 
> I hope, that this is not too off topic for this list, but anyway, it 
> should be easy for any PG-expert.
> 
> I need to run a shell script that logs in to Postgresql, executes a 
> query and logs off again.
> 
> In MySQL, I did it like this:
> 
> 'mysql -u user -ppassword < script.sh'
> 
> My problem is that I can't find a way to put the password in an 'psql' 
> statement at the prompt.
> 
> Any suggestions are welcome!

"Don't do that"

You CAN do something like 
% psql -f dbscript database
Password: <typeity>
<stuff happens>
129195981 INSERT
%

-- 
David Terrell            | "I went into Barnes and Noble to look for a 
Prime Minister, Nebcorp  | book on A.D.D., but I got bored and left." 
dbt@meat.net             | - Benjy Feen
http://wwn.nebcorp.com/  |

Sat, 12 Jan 2002 00:32:05 -0800
David Terrell <dbt@meat.net>
Re: Postgres in bash-mode
On Sat, 2002-01-12 at 03:32, David Terrell wrote:
> On Thu, Jan 10, 2002 at 09:07:50AM +0100, Alexander Pucher wrote:
> > Hi,
> > 
> > I hope, that this is not too off topic for this list, but anyway, it 
> > should be easy for any PG-expert.
> > 
> > I need to run a shell script that logs in to Postgresql, executes a 
> > query and logs off again.
> > 
> > In MySQL, I did it like this:
> > 
> > 'mysql -u user -ppassword < script.sh'
> > 
> > My problem is that I can't find a way to put the password in an 'psql' 
> > statement at the prompt.
> > 
> > Any suggestions are welcome!
> 
> "Don't do that"
> 
> You CAN do something like 
> % psql -f dbscript database
> Password: <typeity>
> <stuff happens>
> 129195981 INSERT

Just a bit of extra info. Passwords on the command line are sniffable.
You can obsure them somewhat, but AFAIK there is no way, or at least no
general way to secure them fully.

If you absolutely need to do something like this, look into expect.

--
Karl

12 Jan 2002 09:03:44 -0500
Karl DeBisschop <kdebisschop@range.infoplease.com>
Re: Postgres in bash-mode