在Debian系统中,使用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,3,5表示1、3和5。-:用于指定一个范围,例如1-5表示1到5。/:用于指定步长,例如*/2表示每隔2个单位。以下是一些示例:
* * * * * command-to-be-executed
0 1 * * * command-to-be-executed
0 1 1 * * command-to-be-executed
0 1 * * 0 command-to-be-executed
要编辑当前用户的crontab文件,请在终端中运行以下命令:
crontab -e
要查看当前用户的crontab文件,请运行:
crontab -l
要删除当前用户的crontab文件,请运行:
crontab -r
请注意,crontab任务调度是基于系统时间的,因此请确保系统时间设置正确。