工具
Web 开发
Web 服务
crontab
crontab 的时间设置,可通过 crontab.guru 测试:
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * [user-name] <command to be executed>
crontab 快速入门
/var/log/cron
crontab 执行日志/etc/crontab
crontab 设置文件/etc/cron.d/
crontab 设置文件路径
查看当前设置(sudo
查看 root 的 crontab 设置):
$ crontab -l
$ sudo crontab -l
编辑 crontab(sudo
编辑 root 的 crontab):
$ crontab -e
$ sudo crontab -e
crontab 常见配置
每分钟执行一次:
* * * * *
以 5 分钟的整倍数时间执行一次(例如第 5, 15, 20, 25 分钟执行等):
*/5 * * * *
每小时执行一次:
0 * * * *
以 6 小时的整倍数时间执行一次(例如 6:00, 12:00, 18:00 等):
0 */6 * * *
每天 00:00 执行一次:
0 0 * * *
每天 6:30 执行一次:
30 6 * * *
每个月的 1 日凌晨执行一次:
0 0 1 * *
每年的 4 月 1 日执行一次:
0 0 1 4 *