Scheduled tasks: that something is executed alone
What you get: an order that is executed on its own every so often - a cleaning, a copy, the WordPress cron - without you having to remember.
Before starting
Be clear what order you want to execute and how often. If the command does not work when you write it by hand via SSH, it will also not work programmed: try it first (Log in to your site via SSH).
Steps
Websites → Scheduled tasks menu.
New task.
Order — the command to execute. Always use full paths: a scheduled task does not have the same environment as your terminal.
When - five boxes: minute, hour, day, month and day of the week. The panel itself explains it: “*” means “every”. For example,
*/5 * * * *means every 5 minutes, and0 2 * * *means every day at 2:00.Description — add one. Within six months you won’t remember what it was for.
Create task.
Tasks can be paused and activated from its row, without deleting them.
Hours that it is convenient to choose
Don’t put everything at 0:00 or 3:00 on the dot: it’s the time that everyone puts everything. A strange minute - 3:17, for example - is just as good and crosses less things.
And don’t put what you don’t need every minute. A heavy task every minute crushes itself: it starts the next one before the previous one is over.
How to check it worked
Don’t wait until tomorrow. Put the homework every 5 minutes temporarily (*/5 * * * *), wait for it to pass once, check that you have done your homework —the file you create, the line you delete— and then put the real schedule on it.
Common problems
- «The schedule is not valid»
The message is: use numbers, the asterisk, ranges such as
1-5or steps such as*/15. It is almost always an extra space or a comma where there was a slash. It is five boxes, neither four nor six.- «Enter the command that has to be executed»
The command field is empty. It is the one that says what is being executed, not the description.
- The task does nothing and it works by hand
This is the most common case and almost always it are the paths. Write complete paths for the program and for the files, because a programmed task does not start from your folder or know your shortcuts.
- The WordPress cron does not run if no one enters the website
That’s how it is by design: WordPress’s cron is activated with visits. If your website has little traffic, schedule here a task that calls wp-cron.php every 15 minutes and disable the internal cron.
- I receive emails every time it is executed
A scheduled task sends by email what it writes on the screen. If you don’t want those notifications, send the output to a log file instead of leaving it loose.
- The task takes longer than its break lasts
You will end up with several copies fighting at once. Space out the interval, or have the order itself check if there is already another one running before starting.
- I want to stop it for a couple of days without losing the configuration
Use “Pause” in its row. It is saved and you can activate it again whenever you want.
- I need the last day of each month to be executed
There is no box for that. Schedule it every day and let the order itself check if tomorrow is the 1st; it’s the way it’s always been and it works in all months.