【linux】crontab定时任务 不执行的问题排查

今天一位朋友问我:老范 我的定时任务咋不执行,命令如下:

* * * * * /usr/bin/curl  http://www.test.com/index.php?a=login&m=crontab   >> /home/laofandata/cron.log 2>&1

随即开始排查:

1 单独访问了这个url。成功!

2 我登陆宝塔面板。添加了访问url的定时任务。 可以正常请求

3 查看服务器cron服务。发现没启动。 开启下:

service crond start

4 新增一个定时任务,访问百度,并写入日志 , 显示成功

* * * * * /usr/bin/curl  http://www.baidu.com   >> /home/laofandata/cron_baidu.log 2>&1

此时我就纳闷了。。为啥那个还不行呢。 查询了资料发现一个问题。我们的链接中 带 & 符号。 curl 服务不能正常解析,访问不到。修改如下:

* * * * * /usr/bin/curl  'http://www.test.com/index.php?a=login&m=crontab'   >> /home/laofandata/cron.log 2>&1

其实就是在 这个连接上 加了 单引号 ! 完美解决!

番外:

Centos cron命令

service crond start 
service crond stop 
service crond reload
service crond status 

Ubuntu上。你需要把 crond 换成 cron

service cron start 
service cron stop 
service cron reload
service cron status 

猜你喜欢

转载自www.cnblogs.com/richerdyoung/p/13396294.html