Introduction to crontab

The Linux system is controlled by the cron (crond) system service. There is a lot of planned work on the Linux system, so this system service is started by default.
The Linux system also provides a command for Linux users to control scheduled tasks: the crontab command.

  • Log file: ll /var/log/cron*
  • Edit file: vim /etc/crontab
  • Process: ps -ef | grep crond ==> /etc/init.d/crond restart
  • Role: task (command) scheduled scheduling (such as: scheduled backup, real-time backup)
  • Brief description: cat /etc/crontab

* Represents all numbers within the range of values. If the month field is *, it means 1 to 12 months;
/ means every certain time interval. For example, the minute field is */10, which means it will be executed once every 10 minutes;
-it means from a certain interval range, which is a closed interval. For example, 2-5 means 2,3,4,5, and 0-23/2 in the hour field means that it will be executed every 2 hours within the range of 0-23 o’clock
;, scattered numbers (not continuous). Such as 1,2,3,4,7,9;

Since the first day of the week is different in various places, Sunday=0 (first day) or Sunday=7 (last day).

crontab configuration example

# 每一分钟执行一次command(因cron默认每1分钟扫描一次,因此全为*即可)
* * * * * command
# 每小时的第3和第15分钟执行command
3,15 * * * * command
# 每天上午8-11点的第3和15分钟执行command
3,15 8-11 * * * command
# 每隔2天的上午8-11点的第3和15分钟执行command
3,15 8-11 */2 * * command
# 每个星期一的上午8点到11点的第3和第15分钟执行command
3,15 8-11 * * 1 command
# 每晚的21:30执行command
30 21 * * * command
# 每月1、10、22日的4:45执行command
45 4 1,10,22 * * command
# 每周六、周日的1 : 10执行command
10 1 * * 6,0 command
# 每小时执行command
0 */1 * * * command
# 晚上11点到早上7点之间,每隔一小时执行command
* 23-7/1 * * * command

 

Guess you like

Origin blog.csdn.net/abc5254065/article/details/112849112