在Ubuntu中,crontab的时间格式遵循以下规则:
* * * * * 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)
每个字段可以包含以下值:
1,2,3 表示在第1、2和3分钟执行命令。1-5 表示从第1到第5分钟。*/5 表示每5分钟执行一次命令。以下是一些示例:
0 1 * * * command-to-be-executed15 * * * * command-to-be-executed0 2 1,15 * * command-to-be-executed0 3 * * 0 command-to-be-executed要编辑crontab文件,请在终端中运行以下命令:
crontab -e
然后按照上述格式添加您的时间和命令。保存并退出编辑器后,新的cron任务将自动生效。