語法:
# .---------------- 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
用法:
# 指定編輯器
crawler$ echo 'export EDITOR="vi"' >> ~/.bashrc
crawler$ source ~/.bashrc
# 列出所有定時(shí)任務(wù)
crawler$ crontab -l [-u USER_NAME]
# 添加定時(shí)任務(wù)(文件名以 'cron' 結(jié)尾)
crawler$ cat crawlercron
# 每 30 分鐘執(zhí)行一次
# 30 * * * * source /path/to/project/env/bin/active && python /path/to/project/manage.py runcron
crawler$ crontab crawlercron
# 清空定時(shí)任務(wù)
crawler$ crontab -r [-u USER_NAME]
例子:
# minute hour day month dayofweek command
# 每分鐘
* * * * * service nginx restart
*/1 * * * * service nginx restart
# 每小時(shí)
* */1 * * * service nginx restart
# 每天 23:00-03:00 的每小時(shí)
* 23-3/1 * * * service nginx restart
# 每天 10:24
24 10 * * * service nginx restart
# 每周末 10:24
24 10 * * 0 service nginx restart
# 每月 1 號(hào)的 10:24
24 10 1 * * service nginx restart
# 每年 1 月 1 號(hào)的 10:24
24 10 1 1 * service nginx restart