linux crontab 命令不执行

概述
  • 环境:centos6.7 + lamp
  • 应用:运用laravel的artisan自己扩展执行脚本
问题

使用crontab配置自动任务,脚本没有任何执行,但是手动执行脚本,就能执行通过,没有任何的问题

解决过程
  • 怀疑文件权限的问题,所以为文件添加了执行权限,未能解决
  • 怀疑脚本本身问题,单独写了一个简单的file_put_contents到一个log文件,每分钟执行一次,在log文件的目录通过执行ll命令,的到信息:You have new mail in /var/spool/mail/root,感觉有眉目,继续下追。
  • /var/spool/mail/root文件,的到内容:
    From root@centos67-x64  Sun Sep 25 22:34:02 2016
    Return-Path: <root@centos67-x64>
    Received: from centos67-x64 (localhost [127.0.0.1])
    	by centos67-x64 (8.14.4/8.14.4) with ESMTP id u8PEY2ia027608
    	for <root@centos67-x64>; Sun, 25 Sep 2016 22:34:02 +0800
    Received: (from root@localhost)
    	by centos67-x64 (8.14.4/8.14.4/Submit) id u8PEY292027604;
    	Sun, 25 Sep 2016 22:34:02 +0800
    Date: Sun, 25 Sep 2016 22:34:02 +0800
    Message-Id: <201609251434.u8PEY292027604@centos67-x64>
    From: root@centos67-x64 (Cron Daemon)
    To: root@centos67-x64
    Subject: Cron <root@centos67-x64> 
    root php /www/laravel/artisan email:send >> /dev/null
    Content-Type: text/plain; charset=UTF-8
    Auto-Submitted: auto-generated
    X-Cron-Env: <LANG=en_US.UTF-8>
    X-Cron-Env: <SHELL=/bin/sh>
    X-Cron-Env: <HOME=/root>
    X-Cron-Env: <PATH=/usr/bin:/bin>
    X-Cron-Env: <LOGNAME=root>
    X-Cron-Env: <USER=root>
    
    /bin/sh: root: command not found
    
  • 通过内容/bin/sh: root: command not found发现是root命令问题,因此通过crontab -e命令运行的时候,不在加user参数,问题的到解决
  • 最终crontab -l结果样式:
    */1 * * * * php /www/laravel/artisan email:send >> /dev/null