maboloshi / Recordum

沙漠之子's 微博客
https://maboloshi.github.io/Recordum
2 stars 0 forks source link

crontab 设定格式 #14

Open maboloshi opened 3 years ago

maboloshi commented 3 years ago

参考: mac下crontab执行定时脚本

格式 (共6列): f1 f2 f3 f4 f5 program 分 时 日 月 周 执行程序

第1列: 分钟1~59 第2列: 小时1~23(0表示子夜) 第3列: 日1~31 第4列: 月1~12 第5列: 星期0~6(0表示星期天) 第6列: 要运行的命令

每10分钟,curl访问一次该地址 */10 * * * * curlhttp://localhost/test.php

每周六、周日的1 : 10重启apache 10 1 * * 6,0 /usr/local/apache/bin/apachectl restart

更多详细,请见下图

crontab举例应用
F1 F2 F3 F4 F5 Program comment
序号 分(0-59) 时(0-23) 日(1-31) 月(1-12) 周几(0-6),周日 0 执行程序 备注
1 1 * * * * curl http:://www.baidu.com 每小时的 01 分, 访问百度
2 1 2 * * * 每天 02:01, 访问百度
3 1 2 3 * * 每月 3 号 02:01, 访问百度
4 1 2 3 * * 4 月 3 号 02:01, 访问百度
5 1 2 3 4 * 每月周五 02:01, 访问百度
6 */10 * * * 5 curl http:://www.baidu.com?param1=a\&param2=b 每10 分钟访问百度, 参数需转义
7 0-50/10 * * * *
8 0 6 1-31/2 * * apachectl resart 隔天上午 6 点重启 apache
9 0 6 */2 * *
10 * */2 * jan mon-wed 1月的周一 至周三,每隔 2 小时重启 apache