在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)
要设置任务间隔时间,您需要根据需求修改这些字段。以下是一些示例:
* * * * * command-to-be-executed
0 * * * * command-to-be-executed
0 1 * * * command-to-be-executed
0 1 * * 0 command-to-be-executed
0 1 1 * * command-to-be-executed
要编辑crontab
文件,请在终端中输入以下命令:
crontab -e
然后按照上述格式设置任务间隔时间,并在相应行中输入要执行的命令。保存并退出编辑器后,新的定时任务将自动生效。