Cron job is not running - php

I've tried just about everything to get my cron script to work but am not having any luck. I've been through many mini tutorial several times too! Here's what I'm trying to run...
/usr/bin/php -q /home/username/public_html/yourfilename.php
On cpanel even i am not getting email after running time of my crone job.
thank you

Try this
/usr/bin/php -q /home/username/public_html/yourfilename.php >/dev/null

You need to check below points.
The file location is correct.
check that the crond services running or not. you can check with below commend :
/etc/init.d/crond status
and you should get status running with pid. if you can got it then move on point 3 otherwise. try to restart the cron service via below command:
/etc/init.d/crond restart
and check the logs via below command :
tail -f /var/log/cron
if you getting the cron service working then check your lfd service working on not.
/etc/init.d/lfd status
if its running then check your email proper configure on lfd.
if lfd fine then run below command as root to add cron
crontab -e
give your cron at the end of file with correct format.
sure that time it will work.
if getting any issue in any point. let me know here.

Related

Cron running "docker exec" make my server freeze

I need help to solve a problem with a cron running a docker exec command.
After setting up this cron, my server sometimes gets not responding anymore. No web requests handled, no SSH connection possible. I must restart the server to get it back. It usually happens 3 or 4 times per day.
My cron is setup in my host's crontab :
* * * * * docker exec -w /home/current myphpapp-container bash -c "php artisan schedule:run >> storage/logs/schedule.log"
I'm pretty sure the cron is faulty here because I never had this problem before the cron installation and I don't get it when I disable the cron script.
Docker version is "18.06.3-ce".
The container is a "php:8.0-fpm".
OS is "Debian GNU/Linux 8 (jessie)".
I searched into syslog and others but did not find anything interesting. My cron is minute but I don't even see any progressive load increasing along time. I'm a bit stuck...
Do you have any ideas ? Where should I look to find relevant logs ?
Ok, finally, it looks like a "Docker engine 18.06" related problem. I created a new fresh server with OS and Docker engine up to date. Problem is gone.

Run cron service when docker build

I have in my docker file :
RUN apt-get -y install cron
RUN cron
COPY symfony.cron /var/spool/cron/crontabs/www-data
RUN chown www-data:crontab /var/spool/cron/crontabs/www-data
CMD ["start.sh"]
And in my start.sh :
echo "+ start cron service"
service cron start
All good, the problem is that crons are not running, and is strange because when I go to the docker container and I do service cron status I get [ ok ] cron is running.
so all good. And when I try to execute one command, is executed well. And when I do crontab -u www-data -l I get the liste with all the crons. So all is good at this point. But the crons are not executed anymore, so I don't understand the problem, maybe some permissions or I don't know. Please help me !!! Thx in advance and sorry for my english.
Any ideas please
You should broadly assume commands like service start don’t work in Docker. Just run the program you’re trying to run directly. Make sure it starts as a foreground process.
CMD ["crond", "-f"]
(If your main container script runs a service start command, and that command exits, and the main container script exits, then the container will exit, which isn’t what you want. If service is backed by systemd or another init system, your container won’t be running that.)

Cron Job command not working

I have a simple script in my server and I need a cron job to make it run every minute. I am using cPanel to set it. What should I enter in the cron job "command" field? I am newbie with cron job commands, I have tried many different options:
/home/enkaizen/public_html/soporte/wp-content/scripts/index.php
/usr/local/bin/php /home/enkaizene/public_html/soporte/wp-content/scripts/index.php
/usr/local/bin/php -q /home/enkaizene/public_html/soporte/wp-content/scripts/index.php
/usr/bin/php /home/enkaizene/public_html/soporte/wp-content/scripts/index.php
/usr/bin/php -q /home/enkaizene/public_html/soporte/wp-content/scripts/index.php
But none seem to be working. I know my script is correct because when I run it manually it does what it is suppose to do.
For in case it helps, my host is https://www.frenzysolutions.com
Any ideas what can I be doing wrong?
To run php from cron try the f flag
php -f /home/enkaizen/public_html/soporte/wp-content/scripts/index.php
It is best practice to use the full path to the executable when using cron. Unfortunately this is distribution/os dependent but it is probably either /usr/bin/php or /usr/local/bin/php
Are you getting any error with "php -q" command ?
Also you can use curl command instead of php -q to execute your scripts through command line.

Cannot execute PHP script periodically using crontab on Ubuntu

I want to execute a php script every 5 minutes. I'm using Ubuntu and I followed these steps:
Executed crontab -e from terminal, entered:
*/5 * * * * /usr/bin/php /var/www/test1.php
in the nano text editor, saved it and started the crontab. It gave no errors and said "installing new crontab", but my script is not being executed. I gave the necessary permissions to the files I use in my script, too.
Any help would be greatly appreciated, thanks.
This is what I use for scheduling cron jobs on apache server in cpanel interface :
/usr/bin/php -q /home/domain_name/public_html/cron_test.php
So, you should specify the path to the php executable too, for making the php script work and execute.

How to write a auto executable script in php?

From the basic of php i know that php needs to have some action/request to execute so i am little confused about how to do it. I know it can be done but don't know how.
I want to write a php script which will run in server every 6 hours and update the database info from an api.
More Info:
The server i am currently working is in linux. But i want to know how i can do it in both linux and windows.
UPDATE:
Cron does not find my script. I don't know where is the problem is. I have used this command in my cpanel
0 */6 * * * php public_html/path_to_dir/file_to_run.php
I have setup the cron so cPanel send me email. The email i am getting is showing some error.
/bin/sh: 0: command not found
Looking forward to your help.
You need to have something run the script on a timer. This is typically going to be cron (on UNIX based systems such as Linux, OS X, BSD, etc) or Windows Task Schedular (on Windows).
You can use crontab to schedule a process in Unix.
I assume that you're using a Linux based S.O.
Install the php5-cli package as
root with apt-get install php5-cli
(or your pkg manager).
Write and test your script
with the PHP CLI, php
filename.php.
Login as selected
user and set up a crontab using
crontab -e
Write the crontab line: * */6 * * * php /full-path/filename.php
/var/log/messages should log the crontab activities.

Categories