Trying to Scheduling Artisan Commands
https://laravel.com/docs/5.0/artisan
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1
Can someone please show me how do I know the /path/to/artisan ?
artisan is in your Laravel project root. So, if your project path looks like /home/laravel-proj/ use this:
* * * * * php /home/laravel-proj/artisan schedule:run 1>> /dev/null 2>&1
extending the answer given by #Alexy Mezenin , to get current working directory on ubuntu use pwd command.
For windows user it may be cd
So if you have a project in desktop/blog.
go to the blog directory and run pwd command and you'll get the path to artisan which is /home/user/Desktop/blog
Then you'll use this:
* * * * * php /home/user/Desktop/blog/artisan schedule:run 1>> /dev/null 2>&1
Artisan is located in your project directory. For instance, my crontab shows something like this:
* * * * * /usr/bin/php /var/www/projectfolder/artisan command
On linux systems:
Using terminal > Go to project folder-> run pwd.The path you should get is the absolute path to your project.
On Windows, I think you need to run cd
Related
I have the following method in my Kernel.php (the one under Console of course):
protected function schedule(Schedule $schedule)
{
$schedule->exec("touch lorem.txt")->everyMinute();
}
And I have the following cronjob added through the cpanel:
* * * * * cd /home/oeit/oe && php artisan schedule:run >> /dev/null 2>&1
I am supposed to see a lorem.txt file in the disk. However when I search for it using find / -name "lorem.txt" the file doesn't appear, which makes me believe that my cronjob is not working properly. I am on a shared hosting.
How do I fix this?
I had to specify the full path for the php executable:
* * * * * cd /home/oeit/oe && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
If you're on shared hosting, it's entirely possible that it is running, but you don't have access to use $schedule->exec on the server.
I would take a look in the storage/logs/laravel.log file to see if you are getting any errors.
I setting on the host this cronjob and it work but, I need local and dont know how it work
my code is:
1 step
open terminal and type
crontab -e
2 step
write this code
* * * * * wget --spider -O - /Applications/XAMPP/xampfiles/htdocs/mysite.local/index.php/cron/comment >/dev/null 2>&1
3 step
save and close file.
but not work... where is problem?
You need to use the absolute path of the script.
* * * * * /usr/bin/wget --spider -O - http://insta.local/cron/comment >/dev/null 2>&1
I have a hard time running cron job on Digitalocean. I noticed there are two different cron files, I get to one by getting to /etc/crontab and other one by entering the command crontab -e.
To make it more confusing, both of those have somewhat different "layout". First one:
* * * * * root php /var/www/Laravel artisan schedule:run >> /home/laravel.log
and second one:
* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log
Here is Laravel scheduler part:
protected $commands = [
'App\Console\Commands\SyncAPIs',
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('media:sync')->everyThirtyMinutes();
// sync for yesterday to eliminate discrepancies
$schedule->command('media:sync ' . Carbon::yesterday())->dailyAt(6);
}
The thing is that the laravel.log does get created, but I see nothing in it, and I don't know if my commands actually get ran. Does that mean that cron IS actually running? How can I debug the issue as I don't see in the database that cron filled it. When I go to the folder /var/www/Laravel and execute the commands which are supposed to be called in scheduler, dataabse fills correctly.
cd ~
crontab -u root -e
* * * * * php /var/www/laravelprojectname/artisan schedule:run 1>> /dev/null 2>&1
service cron restart
grep -i cron /var/log/syslog|tail -3
I think this should help
May be you need to change this line :
* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log
to :
* * * * * /usr/bin/php /var/www/Laravel artisan schedule:run >> laravel.log
I found an answer being actually:
* * * * * php /var/www/Laravel/artisan schedule:run >> laravel.log
php works globally, but artisan needs to be shown the path which is in my Laravel main folder
I am trying to set up scheduler in Laravel.
Here is my crontab which I debugged and works fine - atleast with my cron job
* * * * * /bin/echo "foobar" >> /my_path/example.txt
I don't know if this one works:
* * * * * php /var/www/myproject/artisan schedule:run 1>> /dev/null 2>&1
Here is my schedule function in Kernel:
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->everyMinute();
}
When I am in my project and try php artisan inspire it actually works, so I expected it to fire every minute, but it won't do anything. Nothing happens.
Any ideas?
This part just puts the output into oblivion so you'll never see it:
>> /dev/null 2>&1
Why not try:
* * * * * php /var/www/myproject/artisan schedule:run >> /my_path/example.txt
And check to see if the cron is run in /my_path/example.txt
The default inspire command essentially just echo's a quote so the only way to see it in a cron is to output it to a file on the server.
You can do this using something similar to this:
$schedule->command('inspire')->everyMinute()->appendOutputTo($filePath);
Further details: https://laravel.com/docs/5.4/scheduling#task-output
you should try something
like * * * * * cd /Path/TO/YOUR_PROJECT/ && php artisan schedule:run >> /dev/null 2>&1
Am also using laravel 4.2, Here is my Cron command which currently working good.
0 0 * * * /usr/local/bin/php /*****/******/public_html/artisan command:firemyevent
Hope It will help you.
in my case, I had to explicity a php version compatible with laravel, in my cron job:
cd /path/to/my/project && /usr/local/bin/ea-php71 artisan schedule:run > /dev/null 2>&1
I made it run in mac through:
* * * * * cd /Applications/XAMPP/xamppfiles/htdocs/rcraze && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
You have to put full path of PHP (you can get it through whereis php command in MAC terminal) and pull path of your project.
I'm trying to set up a task every minutes. I put in the crontab as root :
* * * * usr/bin/php /var/www/html/projet1613/artisan schedule:run 1>> /dev/null 2>&1
I can see in the file cron.log that the command is run
Feb 22 13:33:01 serveur-auditpro-1613 CRON[5225]: (root) CMD (usr/bin/php /var/www/html/projet1613/artisan schedule:run 1>> /dev/null 2>&1)
Feb 22 13:33:02 serveur-auditpro-1613 CRON[5225]: (root) CMD (usr/bin/php /var/www/html/projet1613/artisan schedule:run 1>> /dev/null 2>&1)
In my laravel project in the Kernel.php, I put this :
$schedule->command(SaveResult::class)->cron('* * * * *');
When I make the order by myself everything is ok but when it is done every minute by the crontab nothing happens.
Do you have an idea?
Thanks in advance.
Edit log of project :
/bin/sh: 1: usr/bin/php: not found
I don't understand why because when I go in the directory usr/bin there is php.
I'm new to using the scheduling feature so i haven't really looked into it much but is there a reason to "run the task on a custom Cron schedule"? The reason i ask is cause i usually use
$schedule->command(SaveResult::class)->everyMinute();
Haven't had any issues doing it this way
EDIT: Based on your error log you are having issues calling php. If it is in your path, then you should update your cron to * * * * php /var/www/html/projet1613/artisan schedule:run 1>> /dev/null 2>&1
EDIT2: just noticed that the problem is likely due to you calling it usr/bin/php instead of /usr/bin/php