简体   繁体   中英

How to run Laravel schedule command now?

In my kernel.php schedule() in Laravel 8, I have this line.

$schedule->command('exec "cat /var/log/nginx/access.log | grep -v -e "download" -e "danger" -e "/visitor/return" -e "welcome" -e "GET / HTTP" -e "/baby/" -e "/paste/" | awk "{ print $1, $4, $7 }"')->daily()->emailOutputTo($email)->environments('prod');

If I need to test it and need to run right now, what command do I need to run?

I've tried this at the root of the project

php artisan schedule:run >> /dev/null 2>&1

Nothing seems to work, I just don't want to wait for a day to see the result.

You can do that using the tinker console ( php artisan tinker ). The following happens inside tinker.

Get the schedule instance from the container

>>> $schedule = app(Illuminate\Console\Scheduling\Schedule::class)

Get the scheduled event (note that I have not added the daily())

>>> $event = $schedule->command('exec "cat /var/log/nginx/access.log | grep -v -e "download" -e "danger" -e "/visitor/return" -e "welcome" -e "GET / HTTP" -e "/baby/" -e "/paste/"
| awk "{ print $1, $4, $7 }"')->emailOutputTo($email)->environments('prod');

Run the event, supplying the container as a parameter - you could chain this run call above as well, obviously.

>>> $event->run(app())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM