Thread: Re: [SQL] a script that queries database periodically

Re: [SQL] a script that queries database periodically

From
Peter Eisentraut
Date:
Bernie Huang writes:

> My boss wants me to write a script that will send a email report to him
> monthly with the result of database queries.

> I guess a shell script is necessary.  So, is it possible to call
> 'psql' and returning its query result and I can use sendmail to email
> the result? Any other idea?

Conceptually, what you want is something like this:

#! /bin/sh

(
  echo "Here's your report:"
  psql -c 'SELECT ...'
) | mail -s Subject foo@bar

Reading man pages on each of these is advisable.

--
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/