春节假期后又病好几日,每逢佳节倍伤身...。冇乜心情做嘢,搞下啲小测试放松下心情。
网上关于crontab嘅详解多不胜数,但系对 */x 呢种格式嘅执行详情就未见有提及的,都系话“每隔x分钟执行一次”,到底几时开始执行呢?下面系我做一个小测试嘅结果。
*/7 * * * * cd ~/Desktop && python a.py
2014-02-12 12:27:01 [INFO] [root] 2014-02-12 12:27:01.217705
2014-02-12 12:30:01 [INFO] [root] 2014-02-12 12:30:01.243090
2014-02-12 12:33:01 [INFO] [root] 2014-02-12 12:33:01.262853
2014-02-12 12:36:01 [INFO] [root] 2014-02-12 12:36:01.291242
2014-02-12 12:39:01 [INFO] [root] 2014-02-12 12:39:01.316201
2014-02-12 12:42:01 [INFO] [root] 2014-02-12 12:42:01.345312
2014-02-12 12:45:01 [INFO] [root] 2014-02-12 12:45:01.372565
2014-02-12 12:48:01 [INFO] [root] 2014-02-12 12:48:01.407563
2014-02-12 12:51:01 [INFO] [root] 2014-02-12 12:51:01.569072
2014-02-12 12:54:01 [INFO] [root] 2014-02-12 12:54:01.602177
2014-02-12 12:57:01 [INFO] [root] 2014-02-12 12:57:01.630840
2014-02-12 13:00:01 [INFO] [root] 2014-02-12 13:00:01.662817
2014-02-12 13:03:01 [INFO] [root] 2014-02-12 13:03:01.700679
2014-02-12 13:06:01 [INFO] [root] 2014-02-12 13:06:01.728727
2014-02-12 13:09:01 [INFO] [root] 2014-02-12 13:09:01.754044
2014-02-12 13:12:01 [INFO] [root] 2014-02-12 13:12:01.796995
2014-02-12 13:15:01 [INFO] [root] 2014-02-12 13:15:01.830491
2014-02-12 13:18:01 [INFO] [root] 2014-02-12 13:18:01.930805
2014-02-12 13:21:01 [INFO] [root] 2014-02-12 13:21:01.957050
2014-02-12 13:24:01 [INFO] [root] 2014-02-12 13:24:01.983787
2014-02-12 13:27:02 [INFO] [root] 2014-02-12 13:27:02.013302
2014-02-12 13:30:01 [INFO] [root] 2014-02-12 13:30:01.039524
2014-02-12 13:33:01 [INFO] [root] 2014-02-12 13:33:01.069638
2014-02-12 13:36:01 [INFO] [root] 2014-02-12 13:36:01.098836
2014-02-12 13:39:01 [INFO] [root] 2014-02-12 13:39:01.124767
2014-02-12 13:40:01 [INFO] [root] 2014-02-12 13:40:01.149966
2014-02-12 13:45:01 [INFO] [root] 2014-02-12 13:45:01.184718
2014-02-12 13:50:01 [INFO] [root] 2014-02-12 13:50:01.209867
2014-02-12 13:56:01 [INFO] [root] 2014-02-12 13:56:01.243106
2014-02-12 14:00:01 [INFO] [root] 2014-02-12 14:00:01.268636
2014-02-12 14:07:01 [INFO] [root] 2014-02-12 14:07:01.297819
2014-02-12 14:14:01 [INFO] [root] 2014-02-12 14:14:01.323626
2014-02-12 14:21:01 [INFO] [root] 2014-02-12 14:21:01.356585
开始嘅时候系每隔3分钟执行一次,后来改成5分钟,7分钟。根据上面执行结果,所谓嘅“每隔x分钟执行一次”系从全范围最小值开始计起,比如
3嘅时候,佢执行嘅时间队列系[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, ...],
5嘅时候,[0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]
7嘅时候,[0, 7, 14, 21, 28, 35, 42, 49, 56],
值得注意嘅系好似7呢种唔可以整除嘅数作为分隔,最后执行嘅一次系56分,而下一次执行系下一个钟嘅0分,相隔只有4分钟。