Cron job not executing which are not in root folder - php

I have some .php files, some are in root foler and some are inside a directory say "cron_jobs" and I have added cron jobs for these files on server like as below :
*/2 * * * * php /home/public_html/mysite/demo_root.php
*/2 * * * * php /home/public_html/mysite/cron_jobs/demo.php
There are two cron job, where first cron job executing properly but second cron job not executing from server.
And "cron_jobs" directory has permission 755.
Why cron job not executing which are not in root folder?
Is there in any setting for this or Am I doing something wrong to add cron job?

I changed cron job from :
*/2 * * * * php /home/public_html/mysite/cron_jobs/demo.php
To
*/2 * * * * cd /home/public_html/mysite/cron_jobs/ php demo.php
and It is working for me.

Related

Set path in /etc/crontab for php file

Hello I have to run cron which I have written in core php.
Path of my php file in
/var/www/html/xplore/crons/examples/example.php
when I go to path of mu file and run script using php example.php it give me proper output.
But How to give path of file in crontab I have tried it by using
*/2 * * * * root usr/bin/php xplore/crons/examples/example.php
Do you have any idea please help me in to that?
try like below,
*/2 * * * * /usr/bin/php -q /xplore/crons/examples/example.php
*/2 * * * * It means that cron will run in every 2 min.
Seems like the file path that you are passing is wrong. You can try this
*/2 * * * * root /usr/bin/php /xplore/crons/examples/example.php
if this path(xplore/crons/examples/example.php) is correct

Error in cronjob via ssh server

I am trying to set connect cron job via ssh server. i am using command but displaying " no such file or directory ". How can i do this ? Here is my command
/1 * * * * /var/www/html/mysite.com/cron/cron.php
I assume that you are trying to run this cron every minute. Looks like sh script is not getting the correct location of your cron file. I would suggest adding these lines in your cron job.
CRONPATH=/var/www/html/mysite.com/cron
*/1 * * * * cd $CRONPATH; php cron.php

How to run a cron job on OSX for php using MAMP

I've been at this for hours and have tried everything with no luck.
I am basically trying to run this http://docs.phpservermonitor.org/en/latest/install.html#setting-up-a-cronjob
I'm using MAMP and my localhost is a custom folder under User/username/localhost/servercheck
What I've tried so far is.
crontab -e
added */1 * * * * root /usr/bin/php /Users/clientsupport1/localhost/servercheck/cron/status.cron.php
And when I type crontab -l to see if its loaded I see the following.
*/1 * * * * root /usr/bin/php /Users/clientsupport1/localhost/servercheck/cron/status.cron.php
But the script does not run. I even tried a simple script that writes to a file. Still nothing. For some reason the cron job doesn't execute. Any ideas?
You need to call MAMP’s PHP executable, which will depend on on the version of PHP you’re running. For 7.2.1, the following below would be the proper path
*/1 * * * * /Applications/MAMP/bin/php/php7.2.1/bin/php /Users/clientsupport1/localhost/servercheck/cron/status.cron.php

PHP Exec Crontab Not Doing Anything

I am trying to set up a cron job using a PHP script. This works fine on my computer running XAMPP but when I try it on my web host (Just Host) it's not adding it to the list of cron jobs. Here is the PHP code:
exec('crontab cronfile.txt');
cronfile.txt Contents:
* * * * * /usr/bin/php -q /home/-username-/public_html/cron/cron.php 1
This does however work when I add it through cPanel and I can view any cron jobs by using shell_exec('crontab -l'). Any ideas how to resolve this?
Most likely Apache is running as a different user than username, so it won't update usernames crontab file. Run the script
<?php phpinfo()
and verify which user Apache is running as.
On my system, I see the following
User/Group apache(48)/48
You should use this exec('crontab /tmp/cronfile.txt')
and it will work.
You can add every script to this file.
example:
touch /tmp/cronfile.txt
vi /tmp/cronfile.txt
* * * * * path-to-script
* * * * * path-to-script2
.
.
finally
crontab /tmp/cronfile.txt
crontab -l you will see your cron list

cron command with server configration not working at all

I have created following command line to run cron job after every 2minutes
2 * * * * php -f /home/u260451427/public_html/cron/cron_sms_sending_queue.php
my sever configuration look something like that
but its not working.
2 * * * * <command> will run every 2nd minute past every hour.
From 'man 5 cron':
Step values can be used in conjunction with ranges...
Steps are also permitted after an asterisk, so if you
want to say ``every two hours'', just use */2
Therefore your crontab entry should be
*/2 * * * * <command>

Categories