Page 1 of 1

Cron job does not execute

Posted: Fri Dec 11, 2009 11:06 pm
by mih
Hello,

From the CPanel documentation
if I have a file x.php in my www directory, what should I put as the command in the standard cron jobs section to run that file?

You'll need to put the full path to that file as the command. Check the main screen of your cPanel interface for your home directory. It's likely something close to /home/username.

Now, add the directory that the file is in. For example, if your username is ron, and your home directory is /home/ron, you could run that file with /home/ron/www/x.php.

You will need to make sure that x.php is executable. You can check in the File Manager or an FTP program to make sure that the file has permissions necessary for execution (likely 755).

Note: Unless you want x.php to be available to the public, place it in /home/ron/ instead. It doesn't have to be in your www or public_html directory to be run by a cron job.
So I did this the path being

Code: Select all

/home/<my user>/public_html/random.php
and the error (I got it through e-mail)

Code: Select all

/home/<my user>/public_html/random.php: line 1: ?php
: No such file or directory
/home/<my user>/public_html/random.php: line 2: syntax error near unexpected token `"con.php"'
/home/<my user>/public_html/random.php: line 2: `include("con.php");
'
What does it mean ?

random.php starts like that

Code: Select all

<?php
include("con.php");
............
And if I 'execute' the file in the URL it does what it is supposed to do.

Why's that ?

Mihai

Re: Cron job does not execute

Posted: Fri Dec 11, 2009 11:27 pm
by requinix
You have to put a

Code: Select all

#!/usr/bin/php -q
at the very top of the file. That tells the system what it's supposed to use to execute the file.

The /usr/bin/php is the path to the php binary. Yours may be different: cPanel should have a place listing various file paths.

Re: Cron job does not execute

Posted: Fri Dec 11, 2009 11:58 pm
by mih
Thank you tasairis !

That was it.

Now I do not receive an e-mail, it is supposed to be sent even if it is no error.

CPanel:
NOTE: You will receive a message every time this job runs. Using your main e-mail address is not recommended.
But you can't have everything :D . Prefer this rather than the alternative.

Re: Cron job does not execute

Posted: Sat Dec 12, 2009 12:36 am
by requinix
Actually, unless something special is supposed to happen, you'll only get an email if your script outputs anything (in which case the email will contain the script output). No output means no email.