aspirinemaga
aspirinemaga

Reputation: 3937

How to properly execute a CRON job without CPanel?

I've tried to use multiple variations but failed to run properly CRON job since I moved to another hosting.

Before I've just called an http link like so on the pic below:

enter image description here

Filename /cron/synchronize.php contains following code:

<?php shell_exec('php /var/www/domain.com/artisan domaincom:cron argument1 argument2 --option1');?>

I can't find where does the real crontab file is stored, so I could copy the real code...

Now once I'm on new hosting, via terminal I moved to /var/spool/cron and then I typed in command line crontab -e where I placed my code:

SHELL=/bin/bash
HOME=/
0 8,12,14,16,19,23 * * * php /var/www/domain.com/cron/synchronize.php

And that code is not working, anyone who can tell me what am I doing wrong ?

Upvotes: 1

Views: 970

Answers (2)

HPierce
HPierce

Reputation: 7409

Your current cron is set up to run a PHP which then invokes another PHP script. You could greatly simplify this by invoking that command in crontab instead:

0 8,12,14,16,19,23 * * * php /var/www/domain.com/artisan domaincom:cron argument1 argument2 --option1

As others have stated in the comments, it might be helpful for troubleshooting to send the output to a file. This can be done by adding >> ~/output.txt to the end of the command to store the output in the home directory in a file named output.txt (You can of course, pick any other path).

Upvotes: 1

MarkSkayff
MarkSkayff

Reputation: 1374

You should check your user has access to execute cron jobs. When you login to your VPS you login with a specific user (unless you do it with root access).

So you can check at /etc/cron.allow and see if your user is listed there. If it is not you can add your username there in a line. Also check /etc/cron.deny to see if your username is listed, or if ALL is listed there. If ALL is listed there it means you definitely need to add your username to /etc/cron.allow

Upvotes: 1

Related Questions