centos php计划任务,centos6定时任务

1安装crontab:

yum install crontabs

说明:

service crond start //启动服务

service crond stop //关闭服务

service crond restart //重启服务

service crond reload //重新载入配置

查看crontab服务状态:service crond status

手动启动crontab服务:service crond start

查看crontab服务是否已设置为开机启动

chkconfig crond on

2使用创建新任务

1、编辑命令

20190305212521610985.png

创建两个文件

test.php

$fp = fopen("test.txt","a+");

fwrite($fp, date(‘Y-m-d H:i:s‘)."****"."\r\n");

fclose($fp);

?>

给与test.txt操作权限

sudo chmod -R 777 test.txt

创建一个新任务,每一分钟调用一次test.php,修改test.txt

crontab -e

20190305212521902011.png

按 i  进入插入模式

20190305212522281909.png

输入一个新命令

(每一分钟执行这个php命令)

*/1 * * * * php /var/www/html/WexinToken/test/test.php

20190305212522534848.png

退出保存

1按 Esc

2按:

3按wq

4回车

20190305212522853220.png

查看正在运行的定时任务

crontab -l

20190305212523244836.png

重新载入配置文件或者重启服务以开始执行

service crond restart

20190305212523491916.png

如果想要删除配置,执行

crontab -r

no crontab for root 解决方案

主要原因是由于这个liunx服务器 第一次使用 crontab ,还没有生成对应的文件导致的,执行了 编辑(crontab -e)后 就生成了这个文件

[root@localhost ~]# crontab -l

no crontab for root

这个问题非常简单,同样在 root 用户下输入 crontab -e

1 按 Esc

2按:

3按wq

4回车

在输入 crontab -l 就没有问题了

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值