Linux定时任务执行PHP脚本

https://blog.csdn.net/why444216978/article/details/83748136

 

1、检查是否开启crond(默认已安装)   
          service crond status   

          service crond start 

          service crond stop

          service crond restart

2、编辑执行计划
          crontab -e (-l查看计划列表)

          *  *  *  *  *  /usr/local/bin/php     /usr/local/nginx/html/test.php >> test.log

3、重启crond
4、编写对应php文件
5、为php文件加权限chmod 755 test.php
6、检查mysql中数据的变化和test.log日志中的定时任务执行情况
7、查看定时任务日志:vim /var/log/cron 
 

附:部分常用执行计划(分、时、日、月、周)

每1分钟执行一次command

* * * * * command
每小时的第3和第15分钟执行

3,15 * * * * command
在上午8点到11点的第3和第15分钟执行

3,15 8-11 * * * command
每隔两天的上午8点到11点的第3和第15分钟执行

3,15 8-11 */2 * * command
每个星期一的上午8点到11点的第3和第15分钟执行

3,15 8-11 * * 1 command
每晚的21:30重启smb

30 21 * * * /etc/init.d/smb restart
每月1、10、22日的4 : 45重启smb

5 4 1,10,22 * * /etc/init.d/smb restart
每周六、周日的1:10重启smb

10 1 * * 6,0 /etc/init.d/smb restart
每天18 : 00至23 : 00之间每隔30分钟重启smb

0,30 18-23 * * * /etc/init.d/smb restart
每星期六的晚上11:00 pm重启smb

0 23 * * 6 /etc/init.d/smb restart
每一小时重启smb

* */1 * * * /etc/init.d/smb restart
晚上11点到早上7点之间,每隔一小时重启smb

* 23-7/1 * * * /etc/init.d/smb restart
每月的4号与每周一到周三的11点重启smb

0 11 4 * mon-wed /etc/init.d/smb restart
一月一号的4点重启smb

0 4 1 jan * /etc/init.d/smb restart
每小时执行/etc/cron.hourly目录内的脚本

01 * * * * root run-parts /etc/cron.hourly


带url参数的定时任务
一、curl模式:

*/1 * * * * curl http://aaa.***.com/test.php?name=xiaoming&sex=male
1
二、crontab模式

*/1 * * * * /app/bin/php /data/html/aaa.***.com/test.php -name xiaoming -sex male

原文:https://blog.csdn.net/why444216978/article/details/83748136 

总结:关于这个crontab模式我没有调通

解决方案:参考:https://blog.csdn.net/qq_31615139/article/details/53191519?locationNum=8&fps=1

我最后我用workman定时了。。。

 

 

 

 

 

 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值