Linux定时任务Crontab执行PHP脚本
[root@jiangbo ~]# crontab -u root -l no crontab for root [root@jiangbo ~]# crontab -u root -e no crontab for root - using an empty one crontab: installing new crontab [root@jiangbo ~]# crontab -u root -l */1 * * * * ls >> /tmp/ls.txt [root@jiangbo ~]#
*/1 * * * * /usr/bin/php /var/www/html/testcrontab.php
<?php $myfile = fopen("/var/www/html/newfile.txt", "a+");//这里写相对路径不行 //or die("Unable to open file!!"); $txt = "Bill Gates\n"; fwrite($myfile, $txt); $txt = "Steve Jobs\n"; fwrite($myfile, $txt); fclose($myfile); ?>
[root@jiangbo ~]# /usr/bin/php /var/www/html/xiaochu/test/testGame.php
PHP Warning: require_once(../Amfphp/app/util/Mpdo.class.php): failed to open stream: No such file or directory in /var/www/html/xiaochu/test/testGame.php on line 2
PHP Fatal error: require_once(): Failed opening required '../Amfphp/app/util/Mpdo.class.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/xiaochu/test/testGame.php on line 2
[root@jiangbo ~]# crontab -l
*/1 * * * * /usr/bin/php /var/www/html/xiaochu/test/testGame.php
You have new mail in /var/spool/mail/root
[root@jiangbo ~]#
/usr/bin/php 这样执行的话好像不认相对路径,只能通过URL方式定时执行了
[root@jiangbo ~]# /etc/init.d/mysqld start Another MySQL daemon already running with the same unix socket. 正在启动 mysqld: [失败] [root@jiangbo ~]# /etc/init.d/mysqld start 正在启动 mysqld: [确定] [root@jiangbo ~]#
删除/var/lib/mysql/mysql.sock 文件就行了
/sbin/service crond stop //关闭服务
/sbin/service crond restart //重启服务
/sbin/service crond reload //重新载入配置
/sbin/service crond start
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root //如果出现错误,或者有数据输出,数据作为邮件发给这个帐号
HOME=/ //使用者运行的路径,这里是根目录
# run-parts
01 * * * * root run-parts /etc/cron.hourly //每小时执行/etc/cron.hourly内的脚本
02 4 * * * root run-parts /etc/cron.daily //每天执行/etc/cron.daily内的脚本
22 4 * * 0 root run-parts /etc/cron.weekly //每星期执行/etc/cron.weekly内的脚本
42 4 1 * * root run-parts /etc/cron.monthly //每月去执行/etc/cron.monthly内的脚本
Linux定时任务Crontab执行PHP脚本相关推荐
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本(转)
我们的PHP程序有时候需要定时执行,我们可以使用ignore_user_abort函数或是在页面放置js让用户帮我们实现.但这两种方法都不太可靠,不稳定.我们可以借助Linux的Crontab工具来稳 ...
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本
我们的PHP程序有时候需要定时执行,我们可以使用ignore_user_abort函数或是在页面放置js让用户帮我们实现.但这两种方法都不太可靠,不稳定.我们可以借助Linux的Crontab工具来稳 ...
- PHP计划任务:如何使用Linux的Crontab执行PHP脚本(转载)
我们的PHP程序有时候需要定时执行,我们可以使用ignore_user_abort函数或是在页面放置js让用户帮我们实现.但这两种方法都不太可靠,不稳定.我们可以借助Linux的Crontab工具来稳 ...
- linux定时任务(crontab)启动sh脚本
1.启动crond服务 定时任务需要crond服务的支持 # 查看crond状态 systemctl status crond # 启动crond服务 systemctl start crond # ...
- linux+crontab执行php,如何使用Linux的Crontab执行PHP脚本
2016-01-28 回答 一.在crontab中使用php执行脚本 #!/usr/local/bin/php -q 文件名 $file = '/htdocs/www/b100/egspace/bin ...
- linux定时任务不能执行.sh脚本,求助sh脚本手动可以执行crontab不能执行的问题
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 各位老师,我用crontab添加了条*/3 * * * * /usr/bin/sudo sh /usr/sbin/aliddns.sh来运行这个脚本来更新 ...
- linux关机前执行脚本,Linux关机时执行指定脚本
要实现在Linux关机时执行某个脚本的具体思路 1.在文件夹 /etc/init.d/ 下创建关机时需要执行的脚本 file_name; 2.分别在文件夹 /etc/rc0.d/ 和 /etc/rc6 ...
- [老男孩笔记系列]-之linux定时任务crontab命令详解
linux定时任务crontab命令详解 1.1指令语法 crontab [ -u user ] file crontab [ -u user ] { -l | -r | -e } 1.2指令说明 通 ...
- linux cron 服务,Linux定时任务Crontab详解(推荐)
今天做了个数据库的备份脚本,顺便系统得学习一下linux下定时执行脚本的设置.Linux下的定时执行主要是使用crontab文件中加入定制计划来执行,设置比Windows稍微复杂一些(因为没有图形界面 ...
最新文章
- Redis中主、从库宕机如何恢复?
- 分布式缓存redis 方案_Redis缓存和MySQL数据一致性方案详解
- 3万字细品数据倾斜(建议收藏)
- C++和Python的交互
- 历史文件夹_Win10备份文件教程:备份到OneDrive,文件历史记录
- linux系统服务设置命令--chkconfig命令参数及用法详解
- STM32 TIMER DIAGRAM
- Java代码生成器——基于模板快速生成web项目结构
- hbase基础操作命令
- 硬盘数据恢复原理与方法(转)
- 云计算时代迎接挑战方能脱颖而出
- excel 公式常见错误怎么处理
- 技术融合:使用区块链的5G——未来无线通信的序章
- java lint_提高你的代码稳定性与可读性-lint工具
- 从 0 到 1 开发一个聊天通讯 服务 复盘总结
- [ROC-RK3568-PC] [Firefly-Android] 10min带你了解ADC的使用
- 科技周刊第七期:关于熟练程度的等级
- 【GATK加速】作为BWA/GATK软件的替代者,Sentieon 202010版本更新细节
- git打patch__2019.08.07
- 5G专网成行业融合“敲门砖”