Koozali.org: home of the SME Server

CRON - This is driving me nuts

Offline cbacani

  • *
  • 111
  • +0/-0
CRON - This is driving me nuts
« 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

Offline David Harper

  • *
  • 653
  • +0/-0
  • Watch this space
    • Workgroup Technology Solutions
Re: CRON - This is driving me nuts
« Reply #1 on: November 23, 2008, 04:19:25 AM »
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.

Code: [Select]
mkdir -p /etc/e-smith/templates-custom/etc/crontab/
vi /etc/e-smith/templates-custom/etc/crontab/90myjob
expand-template /etc/crontab

Offline cbacani

  • *
  • 111
  • +0/-0
Re: CRON - This is driving me nuts
« Reply #2 on: November 23, 2008, 04:33:02 AM »
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

Offline David Harper

  • *
  • 653
  • +0/-0
  • Watch this space
    • Workgroup Technology Solutions
Re: CRON - This is driving me nuts
« Reply #3 on: November 23, 2008, 04:36:28 AM »
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

Offline cbacani

  • *
  • 111
  • +0/-0
Re: CRON - This is driving me nuts
« Reply #4 on: November 23, 2008, 04:45:07 AM »
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

Offline David Harper

  • *
  • 653
  • +0/-0
  • Watch this space
    • Workgroup Technology Solutions
Re: CRON - This is driving me nuts
« Reply #5 on: November 23, 2008, 04:51:15 AM »
I think there are some syntax errors in your job:

Code: [Select]
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.

Offline cbacani

  • *
  • 111
  • +0/-0
Re: CRON - This is driving me nuts
« Reply #6 on: November 23, 2008, 04:59:04 AM »
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

Offline David Harper

  • *
  • 653
  • +0/-0
  • Watch this space
    • Workgroup Technology Solutions
Re: CRON - This is driving me nuts
« Reply #7 on: November 23, 2008, 05:05:57 AM »
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, which is supported by Stephen Noble, a core SME developer. Purchase options are here.

EDIT: 100th post! 8-)
« Last Edit: November 23, 2008, 05:09:03 AM by davidiwharper »

Offline cbacani

  • *
  • 111
  • +0/-0
Re: CRON - This is driving me nuts
« Reply #8 on: November 23, 2008, 05:12:16 AM »
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

Offline janet

  • *****
  • 4,812
  • +0/-0
Re: CRON - This is driving me nuts
« Reply #9 on: November 23, 2008, 05:33:16 AM »
cbacani

Here's a simple example using /etc/cron.d
Vary the concept to suit.

http://wiki.contribs.org/ShadowCopy#Setup_Cron
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: CRON - This is driving me nuts
« Reply #10 on: November 23, 2008, 10:10:48 AM »
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.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: CRON - This is driving me nuts
« Reply #11 on: November 23, 2008, 10:15:08 AM »
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):
Quote from: PHP command line help
Code: [Select]
[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 ~]#
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)

Offline cbacani

  • *
  • 111
  • +0/-0
Re: CRON - This is driving me nuts
« Reply #12 on: November 23, 2008, 04:23:18 PM »
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

Offline warren

  • *
  • 293
  • +0/-0
Re: CRON - This is driving me nuts
« Reply #13 on: November 23, 2008, 09:00:15 PM »
I have php script running ( called from cron.hourly )
Perms on the php script :
740  admin:www

Offline cbacani

  • *
  • 111
  • +0/-0
Re: CRON - This is driving me nuts
« Reply #14 on: November 24, 2008, 08:23:25 AM »
Warren,

Thank you for the info. Did you have to add anything to the header of the php script?

Carl

Offline warren

  • *
  • 293
  • +0/-0
Re: CRON - This is driving me nuts
« Reply #15 on: November 24, 2008, 08:45:16 AM »
No, its standard php script ie

<?....
do something...

?>

Offline cactus

  • *
  • 4,880
  • +3/-0
    • http://www.snetram.nl
Re: CRON - This is driving me nuts
« Reply #16 on: November 24, 2008, 12:33:44 PM »
No, its standard php script ie

<?....
do something...

?>
No a standard php script should look like:

Code: [Select]
<?php
do something...
?>

As most of the time PHP is not configured to support short opening tags.
Be careful whose advice you buy, but be patient with those who supply it. Advice is a form of nostalgia, dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than its worth ~ Baz Luhrmann - Everybody's Free (To Wear Sunscreen)