pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
postgres on the comman line
4+ messages / 4 participants
[nested] [flat]

* postgres on the comman line
@ 2005-09-22 13:55  "Michael Höller" <MichaelHoeller@t-online.de>
  0 siblings, 3 replies; 4+ messages in thread

From: "Michael Höller" @ 2005-09-22 13:55 UTC (permalink / raw)
  To: pgsql-sql



Hello,

I like to automate a daily check and like to run select statement via
cron but this seems to be more tricky than I thought....

I tried the following:
su postgres -c "select count(*) from TABLE where xxxxxx;"

I have the probelm that I am allways asked for the password - I did not
find a way how to pass the password. 

Also I like to direct the result to a file, I assume I can do this via >
but not haveing passed the first problem I did not check this. 

I am happy for every hint

Thanks a lot 
Michael






^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: postgres on the comman line
@ 2005-09-22 14:13  Thomas Pundt <mlists@rp-online.de>
  parent: "Michael Höller" <MichaelHoeller@t-online.de>
  2 siblings, 0 replies; 4+ messages in thread

From: Thomas Pundt @ 2005-09-22 14:13 UTC (permalink / raw)
  To: pgsql-sql@postgresql.org, "Michael Höller" <MichaelHoeller@t-online.de>

Hi Michael,

On Thursday 22 September 2005 15:55, Michael Höller wrote:
| I like to automate a daily check and like to run select statement via
| cron but this seems to be more tricky than I thought....
|
| I tried the following:
| su postgres -c "select count(*) from TABLE where xxxxxx;"

you mean 

  su - postgres -c "echo 'select count(*) from TABLE where xxxxxx;'|psql"

?

| I have the probelm that I am allways asked for the password - I did not
| find a way how to pass the password.

search the documentation for the .pgpass file. It should contain lines 
with colon separated values consisting of host:port:database:user:password
and must not be world-readable.

| Also I like to direct the result to a file, I assume I can do this via >
| but not haveing passed the first problem I did not check this.

yes.

Ciao,
Thomas

-- 
Thomas Pundt <thomas.pundt@rp-online.de> ---- http://rp-online.de/ ----




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: postgres on the comman line
@ 2005-09-22 14:15  A. Kretschmer <akretschmer@despammed.com>
  parent: "Michael Höller" <MichaelHoeller@t-online.de>
  2 siblings, 0 replies; 4+ messages in thread

From: A. Kretschmer @ 2005-09-22 14:15 UTC (permalink / raw)
  To: pgsql-sql

am  22.09.2005, um 15:55:53 +0200 mailte "Michael Höller" folgendes:
> 
> 
> Hello,
> 
> I like to automate a daily check and like to run select statement via
> cron but this seems to be more tricky than I thought....
> 
> I tried the following:
> su postgres -c "select count(*) from TABLE where xxxxxx;"

- run the cron direcly as postgres
- echo "select foo from bar" | psql ...


or:

write your sql-query i a file and "psql -f file"

> 
> I have the probelm that I am allways asked for the password - I did not
> find a way how to pass the password. 

put it in the ~/.psqlrc


> 
> Also I like to direct the result to a file, I assume I can do this via >

yes, this is possible.


Regards, Andreas
-- 
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47212,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    === 



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: postgres on the comman line
@ 2005-09-22 14:19  Achilleus Mantzios <achill@matrix.gatewaynet.com>
  parent: "Michael Höller" <MichaelHoeller@t-online.de>
  2 siblings, 0 replies; 4+ messages in thread

From: Achilleus Mantzios @ 2005-09-22 14:19 UTC (permalink / raw)
  To: "Michael Höller" <MichaelHoeller@t-online.de>; +Cc: pgsql-sql

O "Michael Höller" Ýãñáøå óôéò Sep 22, 2005 :

> 
> 
> Hello,
> 
> I like to automate a daily check and like to run select statement via
> cron but this seems to be more tricky than I thought....
> 
> I tried the following:
> su postgres -c "select count(*) from TABLE where xxxxxx;"

Firstoff, 'select' is nor a unix command, neither
a postgresql program.
So you need something like:

su postgres -c "psql -c 'select count(*) from TABLE where xxxxxx'"

If you are the only one with an account on the machine
then you might try to tweak ~postgres/data/pg_hba.conf
and set method 'trust' for local access (no tcpip,psql without the -h 
option) .

Also you could set env variables PGPASSWORD, PGUSER.

> 
> I have the probelm that I am allways asked for the password - I did not
> find a way how to pass the password. 
> 
> Also I like to direct the result to a file, I assume I can do this via >
> but not haveing passed the first problem I did not check this. 
> 
> I am happy for every hint
> 
> Thanks a lot 
> Michael
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
> 
>                http://archives.postgresql.org
> 

-- 
-Achilleus




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2005-09-22 14:19 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-09-22 13:55 postgres on the comman line "Michael Höller" <MichaelHoeller@t-online.de>
2005-09-22 14:13 ` Thomas Pundt <mlists@rp-online.de>
2005-09-22 14:15 ` A. Kretschmer <akretschmer@despammed.com>
2005-09-22 14:19 ` Achilleus Mantzios <achill@matrix.gatewaynet.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox