Cron Job Scheduled did not run on specified time - php

I scheduled a cron job to hit a page 1st of every month at 12.00AM but the cron didn't work for some reason.
The below is the cron I have used :
0 0 1 * * /usr/bin/php /var/www/html/cronleave.php >/dev/null 2>&1
Any help will be appreciated.

using sample :
0 0 1 * * wget -O /dev/null -o /dev/null http://www.domain.com/cronleave.php >/dev/null 2>&1
and check time server

Related

Cron Job with PHP and an increment variable argument

I would like to know of it is possible to execute a Cron job every 30 seconds and increment an argument from a value (1 for exemple) to another (50000) :
Like :
wget https://mon-url.com/file/cron.php?id=1 >/dev/null 2>&1
wget https://mon-url.com/file/cron.php?id=2 >/dev/null 2>&1
wget https://mon-url.com/file/cron.php?id=3 >/dev/null 2>&1
wget https://mon-url.com/file/cron.php?id=4 >/dev/null 2>&1
....
wget https://mon-url.com/file/cron.php?id=50000 >/dev/null 2>&1
Is there any command to do that programaticaly ?
Thanks
As suggested before i'd rather go with bash script like this (or similar):
#!/bin/bash
i=1;
while [ $i -le 5 ]
do
wget https://mon-url.com/file/cron.php?id=$i >/dev/null 2>&1
i=$(($i+1));
sleep 30
done
Regards.
Ps. change 5 after -le to whathever you need
Look here below you want:
$x = 1; // You value set to minim
$y = 50000; // Your value set to maxim
while($x <= $y) {
echo "wget https://mon-url.com/file/cron.php?id=$x >/dev/null 2>&1";
$x++;
}
You can use this in your script for cron jobs. Good look!
Perhaps u can just export your counter incrementing it by one every time
COUNTER=0
*/30 * * * * wget https://mon-url.com/file/cron.php?id="$COUNTER" >/dev/null 2>&1 && export COUNTER=$((COUNTER+1))

One command - two cron job

I need to execute in one command two php files.
the second file need to run right after the first finish.
This is what i did, not sure if it's ok:
/usr/bin/wget -O /dev/null -o /dev/null https://example.com/scripts/cron.php; sleep 2; wget -q -O - https://example.com/cron2.php > /dev/null 2>&1
I added sleep between the commands, it will work?
You can use && for sequential execution of command,
check https://www.steveroot.co.uk/2010/07/05/cron-multiple/ And What is the purpose of "&&" in a shell command?
In Your case You can try :
01 00 * * * //usr/bin/wget -O /dev/null -o /dev/null https://example.com/scripts/cron.php && wget -q -O - https://example.com/cron2.php > /dev/null 2>&1
Hope these will Help.

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

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

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

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