任务调度未找到命令“ app”,但有16个类似的命令

时间:2018-06-22 16:25:59

标签: laravel

我试图使用计划自动任务,但是什么也不会发生

* * * * * root /usr/bin/php /home/user/laravel/artisan schedule:run >> /home/user/cron.log 2>&1

所以我尝试使用下面的命令直接调用作业

* * * * * root /usr/bin/php /home/user/laravel/artisan email:panelReport >> /home/user/cron.log 2>&1

输入上面的命令后,我将这个错误保存在cron.log

No command 'app' found, but there are 16 similar ones
app: command not found

如果我运行php aritsan email:panelReport,我将收到一封电子邮件。

Kernel.php

protected $commands = [
    Commands\EmailPanelReport::class
];

protected function schedule(Schedule $schedule)
{

    $schedule
        ->command('email:panelReport')
        ->everyMinute()
}

EmailPanelReport.php

protected $signature = 'email:panelReport';
protected $description = 'Send out weekly report';

public function __construct()
{
    parent::__construct();
}

public function handle()
{
    $panels = Orders::where('orders.prefix', 'P')->get();
    $columns = array ('Date', 'Order Number', 'Description');


    if ( !ini_get("auto_detect_line_endings")) {
        ini_set("auto_detect_line_endings", '1');
    }

    try
    {

        $csv = Writer::createFromFileObject(new SplTempFileObject());
        $csv->insertOne($columns);
        $csv->insertAll($panels->toArray());

        $output = $csv->getContent();

        Mail::raw('See attached', function($message) use ($output)
        {
            $message->to('test@gmail.com');
            $message->subject("test");
            $message->attachData($output, 'test.csv', [
                'mime' => 'text/csv',
            ]);
        });

        $this->info("local");
    }
    catch (\Exception $ex)
    {
        $this->error($ex->getMessage());
        Mail::raw($ex->getMessage(), function($message)
        {
            $message->to('myemail@me.com');
        });
    }
}

系统信息:

  • Ubuntu 16.04
  • nginx / 1.10.3
  • php 7.1.7

我尝试过的其他方式

* * * * * root /usr/bin/php /home/user/laravel/artisan email:panelReport >> /home/user/cron.log 2>&1
* * * * * root /usr/bin/php usr/share/nginx/www/laravel/artisan email:panelReport >> /home/user/cron.log 2>&1
* * * * *  /usr/bin/php /home/user/laravel/artisan email:panelReport >> /home/user/cron.log 2>&1
* * * * *  root /usr/bin/php /home/user/laravel/artisan schedule:run >> /home/user/cron.log 2>&1

1 个答案:

答案 0 :(得分:0)

您可以使用crontab编辑器来编写命令来安排它:

crontab -e

并将您的命令粘贴到文件末尾,退出并保存。结果应如下所示:

# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

要查看计划的命令运行,请执行以下操作:

crontab -l

希望对您有帮助!