Re: connecting in shell scripts ?? - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: connecting in shell scripts ??
Date
Msg-id Pine.LNX.4.30.0101041630080.23778-100000@aguila.protecne.cl
Whole thread Raw
In response to connecting in shell scripts ??  ("Anand Raman" <araman@india-today.com>)
Responses Re: connecting in shell scripts ??  (Larry Rosenman <ler@lerctr.org>)
List pgsql-general
On Thu, 4 Jan 2001, Anand Raman wrote:

> hi guys
> I wish to connect to the database thru a cron job and do some sql queries,,
> However i am having problems in connecting to the database thru the shell
> script.. I am unable to pass the password..
> I have been trying to do the following
>
> #! /bin/sh
> psql -h localhost db1 -U foo -c "select current_timestamp" < passwdfile
> where passwdfile has the passwd for the connection

How'bout something like

#!/bin/sh
USER=foo
DBNAME=db1
PASS=password_for_foo
psql -U $USER $DBNAME << EOF
$PASS
SELECT current_timestamp;
EOF

When processing for output, you have to check for the prompt
"Password:", though. Maybe there's a better way...

--
Alvaro Herrera (<alvherre[@]protecne.cl>)


pgsql-general by date:

Previous
From: Michael Davis
Date:
Subject: RE: Table msysconf
Next
From: Soma Interesting
Date:
Subject: Test for existence of Table