Detailed explanation of using crontab to create timed tasks under Linux

Time:2020-5-21

Under Linux, crontab can be used to create timed tasks.

Common collocation

Crontab – e edit task

Crontab – L view all tasks [this user]

Crontab – R cancel all tasks [the user]

Task format

Command (specific task)

The first five parameters represent time, in order:

Parameter range

Minutes 0-59

Hour 0-23

Date 1-31

January to December

Sunday 0-6 (0 for Sunday)

Special symbols

In order to accurately represent the timing, some special symbols are needed to describe the specific task execution time. There are the following symbols:

“/” stands for every, how often

“*” stands for any time

“-” represents a period of time from one moment to another

Represents discrete time

case

0 8  1 1 0command

Execute the command at 8:00 on January 1 every year

*/30 *  * * *command

Command every 30 minutes

0 6-18  * * *command

Command from 6:00 to 18:00 every day

30 6,9,12  * * *command

Command at 6:30, 9:30 and 12:30 every day

0 6-18/3  * * */user/bin/PHP

/var/www/html/ save.php Execute every 3 hours from 6:00 to 18:00 every day with / user / bin / PHP / var / www / HTML/ save.php

be careful

The commands set in crontab are relative paths, so the scripts executed in the commands should be set to absolute paths as far as possible. On the other hand, if there is any output in the script, it will be output to the current user directory, so if there is a path in the script, please set it to absolute path!

Crontab error report will be sent to users by email. The directory under CentOS is / var / spool / mail / user. Long term accumulation may cause excessive space occupation under / var /. Therefore, it should be cleaned up in time. (dG in vi)

The above is a detailed explanation of how to use crontab to create timing tasks under Linux introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support of the developepaer website!