Re: scripting & psql issues

From: Christopher Browne <cbbrowne(at)acm(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: scripting & psql issues
Date: 2004-08-18 20:20:55
Message-ID: m38yccuriw.fsf@wolfe.cbbrowne.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The world rejoiced as dino_vliet(at)yahoo(dot)com (Dino Vliet) wrote:
> Hi folks,
> probably this is a question you've heard so many times
> but I wasn't able to find a solution to it.
>
> I'm using a shell script to create a textfile for me.
> It looks like
> #!/usr/local/bin/bash
> psql -c "select foo from bar;" -d database1 -t
> psql -c "\q" -d database1
> exit 0
>
> The second psql -c "\q" command is used to logout from
> the first database. But I'm not sure whether this is
> correct. How do I mix these sql and psql meta-commands
> otherwise if I want to be able to use myscript >
> output.txt to get the output from this select
> statement in the file output.txt. I'm planning to
> write a cron job for it too.

You oughtn't need to put in the explicit quit, "\q"; the "^D" that
occurs at the end of the input stream would close things out nicely.

> Another issues is passwords. Normally when I log onto
> database1, I have to issue a password because only the
> superuser is trusted in the pg_hba.conf file. However
> for scripts that I want to be able to run in the
> background like this one, I had to add an entry to the
> pg_hba.conf file to trust this user also. But as from
> security point of view, I'm wondering if this is the
> best way to achieve it.

Check the docs for information on the "care and feeding" of .pgpass.
You can put authentication information into $HOME/.pgpass and anything
running using libpq will automatically look there.

The passwords sit there in plain text form; it might be nice to use
some encoded form (similar to the way Apache handles authentication).

But .pgpass at least has the existing merit that you don't have to
have passwords in your scripts.
--
let name="cbbrowne" and tld="acm.org" in name ^ "@" ^ tld;;
http://cbbrowne.com/info/spreadsheets.html
/Utopia-Bold 40 selectfont/n{moveto}def/p{gsave true charpath clip 72
400 n 300 -4 1{dup 160 300 3 -1 roll 0 360 arc 300 div 1 1 sethsbcolor
fill}for grestore 0 -60 rmoveto}def 72 500 n(This signature has been)p
(brought to you by the)p(letter Q and the number 42.)p(Chris Browne)
p(chris(at)cbbrowne(dot)com)p showpage

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Grainne Reilly 2004-08-18 20:27:26 Re: psql - user defined SQL variables
Previous Message Randal L. Schwartz 2004-08-18 20:01:28 Re: Web application: Programming language/Framework: Summary