I tried to run my cronjob via php artisan cronjob:call
on my local machine and I want to append or create a log file in the storage path. But after the cron is finished. There is no file created in the folder. I already php artisan storage:link
but still not working. Did i miss something?
My command in kernel.php
$schedule->command('amazon:getTransportContent')->weekly()->appendOutputTo(storage_path('logs/getTransportContent.log'));
My cronjob output in cmd, I used print
statement in printing.
D:\admin>php artisan amazon:getTransportContent
Running Cron for getTransportContentWed, Mar 3, 2021 4:50 AM
Cron finished Wed, Mar 3, 2021 4:50 AM
Edit: tried using mkdir
but still not working
$schedule->command('amazon:getTransportContent')->weekly()->appendOutputTo(mkdir(storage_path('logs/getTransportContent.log')))
My Answer:
It looks like you are trying to append the output of your cron job to a log file in the storage path. However, the issue might be with the way you are trying to create the log file.
Instead of using `mkdir`, you should use `touch` to create the log file if it doesn't exist. Here is how you can modify your command in `kernel.php`:
php
$schedule->command('amazon:getTransportContent')->weekly()->appendOutputTo(storage_path('logs/getTransportContent.log'));
And then in your cron job output, you can use the `>>` operator to append the output to the log file:
php artisan amazon:getTransportContent >> storage/logs/getTransportContent.log
This will create the log file if it doesn't exist and append the output of your cron job to it. Make sure that the storage path is writable by the web server user.
Rate this post
4 of 5 based on 9526 votesComments