Re: [SQL] a script that queries database periodically

Поиск
Список
Период
Сортировка
От Mathijs Brands
Тема Re: [SQL] a script that queries database periodically
Дата
Msg-id 20001127204444.C57613@ilse.nl
обсуждение исходный текст
Список pgsql-general
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

В списке pgsql-general по дате отправления:

Предыдущее
От: Folke Ashberg
Дата:
Сообщение: Re: [PHP] a script that queries database periodically
Следующее
От: Bernie Huang
Дата:
Сообщение: a script that queries database periodically