首先,进入命令行模式。作为服务器的linux一般都默认进入命令行模式的,当然,我们管理服务器也一般通过putty或者xshell等工具远程连接到服务器。在命令行中键入:
crontab -e
之后就会打开一个文件,并且是非编辑状态,则是vi的编辑界面,通过敲键盘上的i,进入编辑模式,就可以编辑内容。如果要提高效率,直接用php去执行本地php文件是最佳选择,例如:
00 */2 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
这条语句就可以在每2小时的0分钟,通过linux内部php环境执行test/index,注意,这里可不是通过url访问,通过服务器环境来执行,而是直接执行,因为绕过了服务器环境,所以效率当然要高很多。
好了,点击键盘上的Esc键,输入“:wq”回车,这样就保存了设置的定时任务,屏幕上也能看到提示创建了新的定时任务。
crontab时间格式:
分 时 日 月 周
第1列表示分钟1~59 每分钟用或者 */1表示,/n表示每n分钟,例如*/8就是每8分钟的意思,下面也是类推
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
crontab规则详细
0 6 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 4 * * 6 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
5 4 * * 6 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
15 4 * * 6 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
25 4 * * 6 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
35 4 * * 6 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
5 * * 6 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
40 8 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 8 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
41,51 11 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
1-59/10 12-23 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
31 10-23/2 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 15 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 10-23/2 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 15 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
50 17 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 8 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 18 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 8 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 20 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 2 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 9 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 8,9 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
59 23 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
59 23 * * 6 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 0 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
25,35,45,55 9 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
5-59/10 10 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
5,15,25,35 11 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
*/10 13-15 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30,50 8 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 9 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
*/30 10-11 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 13 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0,30 14-15 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
50 23 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 10,16 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 5 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
30 9 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 13 * * 1-5 /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
- 33、每天7:51执行
51 7 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
53 7 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
40 12 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
55 7 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
10 8 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 16 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 20 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
57 7 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 8 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
0 19-23,0-5/1 * * * /user/local/php/bin/php /home/wwwroot/yii(项目根目录) test/index
如果此文对你有所帮助,请随意打赏鼓励作者^_^
微信公众号
微信
最新评论
总共0条评论