Sambith.com 

Cron

After hours of searching on cron sites, these are the most helpful tips.

My own solution for running the cron for a moodle install in powweb in Sept. 2005 was not what I thought. Oh and I put the cron in an etc file outside the public site which was chmod to 700 (though I hear that 644 will do just as well.

I had anticipated 6 items for the moodle cron on powweb

  1. The time identifier, to run every five miutes each item represents: Minute in the hour | Hour of the day | Day of the month | month in the year | day of the week 0=Sunday
    * /5 * * * *
  2. The shebang, which is optional. Depending on the host config it may be necessary to identify the path to the compilation of php so that cron understands what to do. From what I can gather, if php is run via cgi then the shebang is unnecessary (but I wouldn't stake my life on it!).
    /root/to/php/path
  3. An email suppression. I read 2 version of this. one says put a -q here but this actually suppresses the HTTP header output. So long as the script doesn't use echo or print this will prevent the email.
  4. The location of the php script that is to be 'run' by the crontab. Cron has many more things it can do other than run a php script! Always run the path from the root folder. If for any reason it can't run from root, the file should be chmod 755 in order for it to have permission to be run outside it's environment.
    /path/to/the/script.php
  5. If you want to put the log of this script execution into a log then add the following
    >>/path/to/logfile.log
  6. If you want to put any errors into a log then add
    2>>/path/to/error/log.err
  7. Another alternative to the suppress email is to include this code at the end, but I found no explanation to its cryptic content
    >/dev/null 2>&1

So this is what I thought my crontab would be:

  • */5 * * * * /usr/local/bin/php -q /www/i/icoachnewyor/htdocs/courses/admin/cron.php >>/www/i/icoachnewyor/logs/cron.log 2>>/www/i/icoachnewyor/logs/cron.err
  • But it didn't run. perhaps the -q was out of place?

    So I used the powweb interface and it produced the following:

  • */5 * * * * /www/i/icoachnewyor/htdocs/courses/admin/cron.php
  • Obviously , no suppression, no log files, but it did the trick

    Links that helped