Re: [SQL] a script that queries database periodically

From: Mathijs Brands <mathijs(at)ilse(dot)nl>
To: Bernie Huang <bernie(dot)huang(at)ec(dot)gc(dot)ca>
Cc: PHP_DB <php-db(at)lists(dot)php(dot)net>, PHP_General <php-general(at)lists(dot)php(dot)net>, PGSQL-SQL <pgsql-sql(at)postgresql(dot)org>, PGSQL-GENERAL <pgsql-general(at)postgresql(dot)org>
Subject: Re: [SQL] a script that queries database periodically
Date: 2000-11-27 19:44:44
Message-ID: 20001127204444.C57613@ilse.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql

On Mon, Nov 27, 2000 at 11:22:45AM -0800, Bernie Huang allegedly wrote:
> Hello,
>
> My boss wants me to write a script that will send a email report to him
> monthly with the result of database queries.
>
> For example, an email would be like:
>
> Monthly report
> +----------+---------+---------------+
> | Vehicles | Mileage | # of Signouts |
> +----------+---------+---------------+
> | Vehicle1 | 10324 | 5 |
> +----------+---------+---------------+
> | Vehicle2 | 19384 | 6 |
> +----------+---------+---------------+
> ...
>
> I was thinking of writing up a PHP script and put into crontab, which is
> somehow easier than a shell script, but PHP is an apache module, so I
> cannot execute PHP under crontab (it has to be executed in a browser
> right?). 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?
>
> Thanks.
>
> - Bernie

Sure you can. You can configure PHP to run seperately from any webserver.
You would then be able to write PHP scripts that can be used just like any
other UNIX scripts, for instance from a crontab.

I don't know if you've configured and built PHP before, but it is actually
not that difficult. However, be sure to look at the INSTALL file that comes
with PHP. What it comes down to is probably the following:

1 - extract PHP source
2 - change to the PHP source directory and execute the following configure
command:
./configure --prefix=/usr/local/standalone-php --without-mysql --with-pgsql
3 - build the source by giving the make command
4 - do a 'make install' after PHP has been succesfully build

A bit off-topic, but I hope this is helpful.

Cheers,

Mathijs

Ps. I just thought of something else. You could write a PHP script that runs
under apache (like your're used to) and request it with wget, lynx or a
similar tool from a crontab. That way you wouldn't need to configure a new
PHP installation.
--
"A book is a fragile creature. It suffers the wear of time,
it fears rodents, the elements, clumsy hands."
Umberto Eco

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jason 2000-11-27 19:54:38 Re: [PHP] a script that queries database periodically
Previous Message Brett W. McCoy 2000-11-27 19:44:25 Re: [SQL] a script that queries database periodically

Browse pgsql-sql by date

  From Date Subject
Next Message Jason 2000-11-27 19:54:38 Re: [PHP] a script that queries database periodically
Previous Message Brett W. McCoy 2000-11-27 19:44:25 Re: [SQL] a script that queries database periodically