"Cron "* (Command Run ON) is a system for automatically running programs and scripts on a server at a specific time.

Scheduler job rules

A cron job consists of 6 columns separated by spaces or tabs. The first 5 columns specify the execution time (Minute, Hour, Day, Month, Day of Week); they can contain a number, a list of numbers separated by commas, a range of numbers separated by a dash - or an asterisk *. All other characters in the string are interpreted as a running command with its parameters.

* * * * * * executable command
| | | | |
| | | -- Day of the week (0 - 7) (Sunday =0 or =7)
| | --- Month (1 - 12)
| | --- Day (1 - 31)
|00 Hour (0 - 23)
----- Minute (0 - 59)

For each specific parameter, you can set multiple values, separated by commas.

For example, if you write 1,4,22 in the hour field, the task will be started at 1 am, 4 am and 10 pm.
You can specify an interval - 4-9 will mean that the program must be started every hour between 4 and 9 o'clock inclusive.
The symbol * means "all possible values". For example, specifying * in the hour field will mean "run every hour".
The symbol / is used to specify an additional periodicity of the task. For example, */3 in the hour field means "every three hours".

What a simple scheduler script (cron) looks like:

0 */3 * * * 2.5 /usr/local/bin/php /home/login/html/cron.php  

The script placed at /home/login/html/cron.php will automatically run every three hours on Tuesday and Friday.

Examples of using the tasks:

Run the job once every hour at 0 minutes

0 */1 * * * * /usr/local/bin/php /home/login/html/cron.php  

Run the job every three hours at 0 minutes

0 */3 * * * * /usr/local/bin/php /home/login/html/cron.php  

Run the task on Mondays at 1:15 a.m

15 1 * * * 1 /usr/local/bin/php /home/login/html/cron.php  

Execute the task on April 5 at 0 hours and 1 minute every year

1 0 5 4 * /usr/local/bin/php /home/login/html/cron.php  

Execute the task on Friday the 13th at 1:13 p.m

13 13 13 * 5 /usr/local/bin/php /home/login/html/cron.php  

Execute the task monthly on the 1st of the month at 6:10 a.m

*If you need to run a program once a day, especially if it requires a lot of resources, run it at night, between 2 and 8 a.m. - the server load is minimal

The cron command "crontab " should be used to control it.

Run the following command to open the crontab of the current user:

$ crontab -e

To open the crontab of the user Alice:

$ crontab -u alice -e

View the contents of the crontab of the current user and the Alice user:

$ crontab -l
$ crontab -u alice -l

By default, user tasks for the cron scheduler are stored in directory /var/spool/cron/.

Updated March 13, 2019