Knowledgebase

Writing the Cron Command Correctly Print

  • cronjobsscheduledtasks, cron, php, email, redirects, guide, howto, solution
  • 0

Getting the command right.

THE STRUCTURE

The interpreter, then the script path, then any arguments.

For PHP: the PHP binary path, then the full path to your script.

USING THE CORRECT PHP VERSION

If your account runs multiple PHP versions, the default binary may not be the one your site uses.

Specify the correct binary if the application requires a particular version.

Ask us if unsure which path to use.

ABSOLUTE PATHS

Always. Cron does not run from your web directory.

A relative path fails silently.

QUOTING

If any path contains a space, quote it.

SUPPRESSING OUTPUT

Redirect output to nothing if you do not want email every run.

Do that only after confirming the job works.

CAPTURING OUTPUT TO A FILE

Better than email for a frequent job.

Redirect to a log file, and rotate or clear it periodically or it fills your disk.

TESTING THE COMMAND

If you have shell access, run it manually first.

If not, set a short schedule and watch for output.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot