Adding Cron to a server is not a difficult task, even though it requires using a terminal and logging in to the server via SSH. This tutorial will show you how to easily add cyclic tasks to a server.
What's the cron syntax?
Crones are saved in the following format, for example: */10 * * * * /usr/bin/curl "https://thecamels.org/wp-cron.php >/dev/null 2>&1
A task has two parts, a rule when the task is to be executed (asterisks) and a command to be executed.
The asterisks mark the time, in order: minutes (0-59), hours (0-23), days of the month (1-31), months (1-12), days of the week (0-6) - with this notation you can set any condition when the task should be executed.
It may seem complicated, but you don't have to learn it at all. Using that tool, you can easily program the time of your task.
Adding a task to Cron
- Log in to the server.
- Enter the following command in the terminal:
crontab -e
- You're in a word processor now. Press
i
, now in the bottom left corner of the terminal you will see- - INSERT - -
, you are in text input mode. - Enter/paste the task to be executed, as described in the previous paragraph.
- When you think that the task is wrote correctly, press the
Esc
key and then:x
to save the changes. - When you exit the editor you will see
crontab: installing new crontab
is a sign that the task has been added correctly.