Koozali.org: home of the SME Server
Obsolete Releases => SME Server 7.x => Topic started by: cbacani on November 23, 2008, 03:45:53 AM
-
Hey,
I spent a lot of time trying to find the 'current' 7.4 way to write a cronjob and have SME run it and all I got was old messages that were no correct, dev manual that is outdate and a program called 'Crontab Manager' that has its own demons.
Can anyone direct me to the real way to have cron run every hour and run a .php script? If you can do this I will write a step-by-step white paper like I did for Shoutcast for the SME server and let the world know how to do this in "simple" tearms.
I am now understanding more and more how these forums are filled with out dated information or information that is off by a little bit, but just enough to make it very hard for someone to understand what it is that you need to do.
Sorry if I am ranting but a cronjob sometime just needs to be done.
Carl
-
It's not exactly the 'proper' way to do it, but you can just use "crontab -e" as root.
I think the proper way is to create a custom template for /etc/crontab.
mkdir -p /etc/e-smith/templates-custom/etc/crontab/
vi /etc/e-smith/templates-custom/etc/crontab/90myjob
expand-template /etc/crontab
-
David,
Thank you for the info. Another issue came up as well. Cron reports that it cannot find the file even though it is where it is stated. Anybody know the reason why?
Carl
-
I think you need to call PHP and give it the .php file as a parameter.
e.g.
/path/to/php /path/to/file.php
-
Lets start this with an example so we can all be on the same page.
Example:
We want to run a cronjob every hour on the hour 7 days a week.
I will for this example call this code below '90test'.
59 * * * * -u root /usr/bin/php -q /home/e-smith/files/ibays/sample/html/cronjob.php
NOTE: Is the above statement correct?
----------------------------------------------------------
So I go and do the following:
vi /etc/e-smith/templates-custom/etc/crontab/90test
now, expand the template by issuing the following command:
expand-template /etc/crontab
Is this correct?
Also, sould there be any special commands to run a .php script also should there be any commands in the script to tell cron that you want it to run a .php script?
T
his information is all over the place in different formats, I just would like to know what really is the proper format so I can write a proper white paper.
Thank You
Carl
-
I think there are some syntax errors in your job:
0 * * * * root /usr/bin/php -q -f /home/e-smith/files/ibays/sample/html/cronjob.php
Notes:
0 - on the hour
-u - no need for it
-f - the -q parameter requires -f
The latter half is correct. Once you have run expand-template, check the complete file by running cat /etc/crontab.
-
David,
So the u for user is no longer required or was it ever required? A lot of messages in this forum have stated that it was needed. The -f and the -q (my guess) are required for the php to be run?
BTW, great thanks for the information as this does help. Do you know of a source that tells the real story (SME specific) about cron? The dev pages seem to be out-of-date.
Carl
-
AFAIK the -u is not required. Look at the auto-generated parts of /etc/crontab and you'll see what I mean. As for the PHP parameters, according to php --help, you can either run:
php <file> (full output)
php -q -f <file> (quiet output)
Unfortunately I've been making this up as we've been going along using my (newish) knowledge of the templating system and Red Hat Enterprise Linux (I've done an entry-level course in it). The best suggestion for you, I think, is that if you are uncomfortable with the command line, you might want to consider obtaining the Dungog crontab manager (http://www.dungog.net/wiki/Dungog-cron), which is supported by Stephen Noble, a core SME developer. Purchase options are here (http://www.dungog.net/wiki/Purchase).
EDIT: 100th post! 8-)
-
David,
I really want to write a white paper on this to make it simple to use the command line. The idea is to learn and pass the information along. Getting the cron manager is a good idea but all of the details on how to do it for yourself are negated and lost. Thank you for you help and I will continue to try and find the necessary information and hence write the write paper.
Carl
-
cbacani
Here's a simple example using /etc/cron.d
Vary the concept to suit.
http://wiki.contribs.org/ShadowCopy#Setup_Cron
-
Do you know of a source that tells the real story (SME specific) about cron?
The only difference to normal cron is that the configuration files are templates as almost all template files on SME Server.
The dev pages seem to be out-of-date.
I am not sure if you are right there. If so please state where you think they are out of date so we can update them, but keep in mind that the SME Server Developer's Guide is (in some sections) geared to writing packages which means things might be a little different as to direct modification on your server.
-
So the u for user is no longer required or was it ever required? A lot of messages in this forum have stated that it was needed. The -f and the -q (my guess) are required for the php to be run?
No, the -f option (to run a file) implies the -q automatically AFAIK and q only suppresses http headers (only needed by browsers):
[root@sme73test ~]# php --help
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
php <file> [args...]
[...]
-f <file> Parse <file>. Implies `-q'
[...]
-q Quiet-mode. Suppress HTTP Header output.
[...]
[root@sme73test ~]#
-
Next issue. Permission denied coming from the email sent to the admin from the cron. Do you need to chmod the php script to 755 as stated in some of the messages and do you have to add anything to the header of the php script file to tell cron to run it as stated in again some of the messages on this forum?
Sorry to be such a pain but the answers and the white paper are coming along thanks to all of you.
Carl
-
I have php script running ( called from cron.hourly )
Perms on the php script :
740 admin:www
-
Warren,
Thank you for the info. Did you have to add anything to the header of the php script?
Carl
-
No, its standard php script ie
<?....
do something...
?>
-
No, its standard php script ie
<?....
do something...
?>
No a standard php script should look like:
<?php
do something...
?>
As most of the time PHP is not configured to support short opening tags.