Crontab(cron table)是用于定时执行任务的工具,其语法格式如下:
* * * * * command-to-be-executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday to Saturday; 7 is also Sunday)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
每个字段可以是一个具体的值、一个范围、一个列表或者一个通配符(*),用于指定任务执行的时间。
以下是一些示例:
0 1 * * * /path/to/command
0 15 * * 0 /path/to/command
0 10 1,15 * * /path/to/command
15 * * * * /path/to/command
要编辑Crontab文件,请在终端中输入crontab -e,然后按照上述格式添加或修改定时任务。保存并退出后,新的定时任务将自动生效。