Managed WordPress Hosting built different 💪

pressypress
Cron jobs

How to add a cron job

  1. Open your Pressy and go to Cron in the sidebar.
  2. Press Add a cron job.
  3. Choose how often — Hourly, Daily, Weekly — and fill in the fields. Or switch to Raw expression and type the five fields yourself.
  4. Enter the command to run.
  5. Check Would next run shows the times you expected.
  6. Press Add cron job.

Commands run as your site's user, from your home folder, with the same PHP as your site. Schedules are read in UTC, and your own clock is shown beside the server's so a 3am job is never ambiguous.

Add a log so you can check it

Nothing records what a cron job did — not whether it ran, how long it took, or what it printed. Add this to the end of your command and it reports on itself:

>> $HOME/cron.log 2>&1

Then read $HOME/cron.log over SSH or FTPS.

Use $HOME, not ~. Cron's shell expands the first reliably and may not expand the second at all, which leaves you a file literally named ~ and no log where you expected one.

The % trap

Cron cuts your command off at the first %. It treats it as a newline and feeds the rest of the line to the command as input, so the job saves happily and never does what you meant.

Anything with a % in it — date +%Y-%m-%d being the usual one — needs \% instead. The screen spots it and offers to fix it for you.

The line that is already there

One cron line is ours and is labelled Ours. It pokes WordPress's own scheduler hourly, because left alone WordPress only runs scheduled tasks when a visitor happens to load a page — which means scheduled posts on a quiet site publish late or not at all.

Leave it in place.

If the job does not seem to run

  1. Check the log file from above. Empty means it is not running.
  2. Run the command by hand over SSH. If it fails there, it will fail on a schedule too.
  3. Use full paths. Cron runs with a minimal environment, so php may need to be the full path to the binary.
  4. Check for an unescaped %.

When to write to us

Write to us if the command works by hand over SSH but produces nothing on a schedule. Send the exact cron line.

Didn’t solve it?

Write to us with your Pressy’s address and what you were doing when it went wrong. Answered by the people who built it.

Last updated