Running Shells as Cron Jobs

A common thing to do with a shell is making it run as a cronjob toclean up the database once in a while or send newsletters. This istrivial to setup, for example:

  1. */5 * * * * cd /full/path/to/root && bin/cake myshell myparam
  2. # * * * * * command to execute
  3. # │ │ │ │ │
  4. # │ │ │ │ │
  5. # │ │ │ │ \───── day of week (0 - 6) (0 to 6 are Sunday to Saturday,
  6. # | | | | or use names)
  7. # │ │ │ \────────── month (1 - 12)
  8. # │ │ \─────────────── day of month (1 - 31)
  9. # │ \──────────────────── hour (0 - 23)
  10. # \───────────────────────── min (0 - 59)

You can see more info here: http://en.wikipedia.org/wiki/Cron

Tip

Use -q (or –quiet) to silence any output for cronjobs.

Cron Jobs on Shared Hosting

On some shared hostings cd /full/path/to/root && bin/cake myshell myparammight not work. Instead you can usephp /full/path/to/root/bin/cake.php myshell myparam.

Note

register_argc_argv has to be turned on by including register_argc_argv
= 1
in your php.ini. If you cannot change register_argc_argv globally,you can tell the cron job to use your own configuration byspecifying it with -d register_argc_argv=1 parameter. Example: php
-d register_argc_argv=1 /full/path/to/root/bin/cake.php myshell
myparam