Thread: Scheduled function ?
Hi, What's the best / easiest way to run a function as a 'scheduled task' ? My current platform is FC2 / PostgreSQL 8.0.2 and the stock report application is in php. BR, -- Aarni Ruuhimäki -------------- This is a bugfree broadcast to you from **Kmail** on **Fedora Core** linux system --------------
On Thu, May 4, 2006 10:37 am, Aarni Ruuhimäki said: > Hi, > > What's the best / easiest way to run a function as a 'scheduled task' ? > > My current platform is FC2 / PostgreSQL 8.0.2 and the stock report > application is in php. Probably cron. Write a script to call the function, then have cron call it at appropriate times. Daniel T. Staal --------------------------------------------------------------- This email copyright the author. Unless otherwise noted, you are expressly allowed to retransmit, quote, or otherwise use the contents for non-commercial purposes. This copyright will expire 5 years after the author's death, or in 30 years, whichever is longer, unless such a period is in excess of local copyright law. ---------------------------------------------------------------
On Thursday 04 May 2006 17:50, Daniel T. Staal wrote: > On Thu, May 4, 2006 10:37 am, Aarni Ruuhimäki said: > > Hi, > > > > What's the best / easiest way to run a function as a 'scheduled task' ? > > > > My current platform is FC2 / PostgreSQL 8.0.2 and the stock report > > application is in php. > > Probably cron. Write a script to call the function, then have cron call > it at appropriate times. > > Daniel T. Staal > Hi, Yes, I thought so. What would the syntax of such a script ? Something like: #!/bin/bash # /usr/local/pgsql/bin/psql db_name run a function ? #eof Cronned for user postgres. BR, Aarni
On Thu, May 04, 2006 at 05:59:42PM +0300, Aarni Ruuhimäki wrote: > > > My current platform is FC2 / PostgreSQL 8.0.2 and the stock report > > > application is in php. > > Probably cron. Write a script to call the function, then have cron call > > it at appropriate times. > Yes, I thought so. What would the syntax of such a script ? why don't you reuse your logic from php, you have already implemented (config for the connection, maybe more). install the php-cli (if not already there with your install) and write the stuff to do in php - then call that script with cron. -- cu
Attachment
On Thu, May 4, 2006 10:59 am, Aarni Ruuhimäki said: > Yes, I thought so. What would the syntax of such a script ? > > Something like: > > #!/bin/bash > # > > /usr/local/pgsql/bin/psql db_name > > run a function ? > > #eof Depending on what I wanted to do, and how complex the function is, I'd probably use: #!/bin/sh /usr/local/pgsql/bin/psql -c "SQL_Function_Call" db_name username #EOF You could also write the SQL to a file and have cron call `/usr/local/pgsql/bin/psql -f SQL_file db_name username`. (If there is output you might want to put that someplace as well.) Daniel T. Staal --------------------------------------------------------------- This email copyright the author. Unless otherwise noted, you are expressly allowed to retransmit, quote, or otherwise use the contents for non-commercial purposes. This copyright will expire 5 years after the author's death, or in 30 years, whichever is longer, unless such a period is in excess of local copyright law. ---------------------------------------------------------------
On Thursday 04 May 2006 18:24, Daniel T. Staal wrote: > On Thu, May 4, 2006 10:59 am, Aarni Ruuhimäki said: > > Yes, I thought so. What would the syntax of such a script ? > > > > Something like: > > > > #!/bin/bash > > # > > > > /usr/local/pgsql/bin/psql db_name > > > > run a function ? > > > > #eof > > Depending on what I wanted to do, and how complex the function is, I'd > probably use: > > #!/bin/sh > /usr/local/pgsql/bin/psql -c "SQL_Function_Call" db_name username > #EOF > > You could also write the SQL to a file and have cron call > `/usr/local/pgsql/bin/psql -f SQL_file db_name username`. > > (If there is output you might want to put that someplace as well.) > > Daniel T. Staal > This works nicely with my test function and is sooo simple. The actual function is written by someone else and is quite a monster so I won't go into even trying to translate it into php with my limited php skills. The app is a simple stock report / view tool and the function roams around the db nightly. Thank you guys again ! BR, Aarni