laravel - 任务调度 未找到命令 'app',但类似的有16个

标签 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 我会很好地收到电子邮件。

内核.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('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="017564727541666c60686d2f626e6c" rel="noreferrer noopener nofollow">[email protected]</a>');
            $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('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7baaeb2bab6bebb97bab2f9b4b8ba" rel="noreferrer noopener nofollow">[email protected]</a>');
        });
    }
}

系统信息:

  • 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

最佳答案

您可以使用 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

希望对您有帮助!

关于laravel - 任务调度 未找到命令 'app',但类似的有16个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50992098/

相关文章:

css - Laravel Sass 包含在 html 中

php - laravel如何根据消息设置类

拉维尔 5.6。 JSONb 列。计数数组

Laravel 记录到自定义 channel

php - Laravel如何编写具有多个条件但记录在同一用户下的搜索查询

laravel - 如果条件匹配,Model::updateOrCreate() 会更新软删除的模型吗?

Laravel:将输入查询的结果更改为友好的 url

mysql - 违反完整性约束 : 1048 Column 'post_id' cannot be null

php - Laravel 5.2 多对多关系与 3 个枢轴列问题

php - Blade 模板可能无法在 Laravel 4.1 中工作?