How set cron job - PHP in digital ocean for daily bases? - php

I have set cron job command on my digital ocean server.
0 1 * * * php /var/www/html/domain/cron/index.php
is it right coded??
Because its not running daily.
Had check of 5mint and hourly, its working fine but not for each day.
Please help me to find out the solution.
Thanks in Advance.

0 1 * * * means your php file will execute on 01:00:00, and this depend on your where your server is located (server's time zone).
Check this site. it will help you to set time for your cron job.
and if your cron is running for 5 minute, it should work for daily basis, you have to just figure out at what time it should run.

Check if your cron commands are OK by typing:
$ crontab -l
or right in
/var/spool/cron/crontab
Your command seems to be OK for a script that will be executed every day at 01AM.

Login to your droplet and then follow this steps
crontab -e
* * * * * cd project_path/ && php artisan schedule:run 1>> /dev/null 2>&1
Example:
* * * * * cd /var/www/html/blog/ && php artisan schedule:run 1>> /dev/null 2>&1

Related

Execute php script with crontab doesn't work

I'm trying to execute a php script every day to send an automatic email to the clients that have contacted me. To try if it works I'm trying to execute it every minute. I have followed these steps:
whereis php prompts
php: /usr/bin/php /usr/share/php /usr/share/man/man1/php.1.gz
2. Then I make crontab -e and add a line:
* * * * * /usr/bin/php /var/www2/www/centros-sbc.com/public_html/mail/mail_automatico.php &>> /dev/null
Then I wait a minute and nothing happens. Have any idea?
Every minute is "* * * * *"
You've done "every hour at one minute past"
Have your tried
/usr/bin/php -f /var/www2/www/centros-sbc.com/public_html/mail/mail_automatico.php &>> /dev/null
-f option is here to execute the file (your file) mail_automatico.php
1) check if your cron job is working (service crond status | systemctl status crond)
2) &>/dev/null is normally equal to > /dev/null 2>&1.
But some shells doesn't support it.
have you tried > /dev/null 2>&1 instead &>/dev/null ?
Finally I succeed by making it more simple:
/usr/bin/php /var/www2/www/centros-sbc.com/public_html/mail/mail_automatico.php
Thanks to all

Laravel + Crontab not working

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.

Laravel schedular works manually but not automatically?

I have this in my Kernal.php:
$schedule->call('removeTemporaryFiles')->everyMinute();
When I hit php artisan schedule:run it works like charm. But I also ran:
* * * * * php /var/www/html/archive/artisan schedule:run >> /dev/null 2>&1
But it is not running automatically. I have waited more than a minute but it is still not running. What am I doing wrong?
And where is the main machine cron saved? The one that runs every minute and calls artisan schedule:run?
In order for Schedules to run, you need first to add the cron job to your cron table. Run this command
sudo crontab -e
Then choose your preferred editor.
Then add the below line:
* * * * * php /var/www/html/archive/artisan schedule:run >> /dev/null 2>&1
Finally in your Kernel.php you add the schedule:
$schedule->command(<artisan command>)->everyMinute();
The documentation is perfectly detailing it.
Finding cron jobs:
Depending on how your linux system is set up, you can look in:
- /var/spool/cron/* (user crontabs)
- /etc/crontab (system-wide crontab)
also, many distros have:
- /etc/cron.d/* These configurations have the same syntax as /etc/crontab
- /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly
These are simply directories that contain executables that are executed hourly, daily, weekly or monthly, per their directory name.
On top of that, you can have at jobs (check /var/spool/at/*), anacron (/etc/anacrontab and /var/spool/anacron/*) and probably others I'm forgetting.
References : https://unix.stackexchange.com/questions/7053/how-can-get-a-list-of-all-scheduled-cron-jobs-on-my-machine

Run PHP script in crontab only works when exporting to a file

On CentOS release 6.5 (Final):
I know that usually I just need to use the following command in crontab to run a php script.
0 * * * * /usr/local/bin/php absolute_path_file_to_the_script.php
But, recently, it stopped working. The only work around is to use the following command
0 * * * * /usr/local/bin/php absolute_path_file_to_the_script.php > log
But I would rather not to output anything to log for now.
So, I even tried
0 * * * * /bin/sh -c "/usr/local/bin/php absolute_path_file_to_the_script.php"
But the above commend is again not working in crontab (it works if I type in the shell directly).
And I am sure that the above command did run in crontab for a second with
ps ux, and then it stopped executing.
Any ideas on how to run the command properly without logging?
Try run that command (only php, without cron settings) from terminal and show result
Both answers from Marc and Greg work:
> /dev/null
or
> /dev/null 2>&1

How to set cron in linux server?

Hi i have created a birthday notification. My Cron URL is http://dev.raddyx.in/bday/birthday.php
I want to set cron run in every 24 hour but i am unable to run in the Linux server.
Check my command:-
50 10 * * * curl -s -o /dev/null http://dev.raddyx.in/bday/birthday.php
Please help me how to set cron in Linux server?
Are you entering this in /etc/crontab? If so, then you will also need to specify the user that the command is to run as, in the sixth field:
50 10 * * * root curl -s -o /dev/null http://dev.raddyx.in/bday/birthday.php
You may want to look in /var/log/cron for some leads on the problem.
Check the CURL is available or not otherwise you can use wget to execute the request
This will execute every 10:50. You can try this also
50 10 * * * /usr/bin/wget -O- http://dev.raddyx.in/bday/birthday.php >> /dev/null
This will dump your errors into this cronerror.txt file
59 10 * * * /usr/bin/wget -q /var/www/<your log folder path>/cronerror.txt http://dev.raddyx.in/bday/birthday.php

Categories