Cron job failure

Status
Not open for further replies.

cartermcpyro

New Member
Messages
14
Reaction score
0
Points
0
I'm trying to set up one cron to run every 5 minutes. It doesn't work. I even removed the -q so it'd email me and it doesn't even email me (I set where to email in the cron tab page). I tried this:
Code:
php-cron /home/pyrokid/public_html/expire.php
And
Code:
php /home/pyrokid/public_html/expire.php
They both don't work. What's so wrong that I'm doing that the cron tab won't even email me the error?

I'd also like to add that the email I'm using to send the cron result to is gmail.
 
Last edited:

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
251
Points
63
From what I can tell (I don't mess with cron much) you need to format your commands like this:

5 17 * * 2 /myscript.php

And you need to make sure the file has executable permissions (755 will work)
 

cartermcpyro

New Member
Messages
14
Reaction score
0
Points
0
From what I can tell (I don't mess with cron much) you need to format your commands like this:

5 17 * * 2 /myscript.php

And you need to make sure the file has executable permissions (755 will work)
So I should used advanced cron? And the file is already 755.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
251
Points
63
I think you can use regular.

Just type in /myscript.php, none of the other stuff. the 5 17 * * 2 is the interval, which is generated for you in easy mode.
 

cartermcpyro

New Member
Messages
14
Reaction score
0
Points
0
Still didn't work. I even set it to 10 minutes. And it still didn't even email me.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
From what I can tell (I don't mess with cron much) you need to format your commands like this:

5 17 * * 2 /myscript.php

And you need to make sure the file has executable permissions (755 will work)

That will try to run /myscript.php (relative to file system root, not docroot) at 5:05 pm every Tuesday. Fix the command by replacing it with "/home/pyrokid/public_html/myscript.php" (or whatever the path to docroot is) and it still won't run unless myscript.php begins with a shebang line (#!/usr/local/bin/php), which would be unusual for a PHP script.

The crontab entry to run a PHP script every 5 minutes should look like:
Code:
*/5 * * * * /usr/local/bin/php /home/pyrokid/public_html/expire.php
This is what the standard cron job entry page in cPanel generates. I don't think the full path to php is necessary, but used it just to be safe. If you want to test the last time the script ran, you could have it touch a file.

What do you get when you access the expire.php script in a web browser? Any errors?
 

cartermcpyro

New Member
Messages
14
Reaction score
0
Points
0
That will try to run /myscript.php (relative to file system root, not docroot) at 5:05 pm every Tuesday. Fix the command by replacing it with "/home/pyrokid/public_html/myscript.php" (or whatever the path to docroot is) and it still won't run unless myscript.php begins with a shebang line (#!/usr/local/bin/php), which would be unusual for a PHP script.

The crontab entry to run a PHP script every 5 minutes should look like:
Code:
*/5 * * * * /usr/local/bin/php /home/pyrokid/public_html/expire.php
This is what the standard cron job entry page in cPanel generates. I don't think the full path to php is necessary, but used it just to be safe. If you want to test the last time the script ran, you could have it touch a file.

What do you get when you access the expire.php script in a web browser? Any errors?
When I run the script in my browser it works perfectly. It connects to mysql, checks the date of a row in the table, and deletes what rows it needs to delete.
 
Messages
740
Reaction score
1
Points
18
I believe that because of user abuse of the cron and it causing servers to crash there was a time limit put on. I cannot remember how long it was for, you may be able to find it in the announcements section (or possibly may have been a post I saw elsewhere here). For a definite answer, if it can't be found in the announcements section of the forum, contact the official support >> http://support.x10hosting.com/
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
251
Points
63
I believe the interval xxll_martin_llxx is talking about is five minutes between cron jobs. There is also a maximum execution time, I believe, but a php script shouldn't take that long unless you're doing something wrong or really bizarre.
 

cartermcpyro

New Member
Messages
14
Reaction score
0
Points
0
I can't even access FTP or my site anmore because my site (and sometimes this forum) don't load and give a page load error. Is something going on with the free servers?
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I can't even access FTP or my site anmore because my site (and sometimes this forum) don't load and give a page load error. Is something going on with the free servers?

They do go down fairly frequently for short periods. Check the status page.

Did my other suggestions make any difference? Assuming you added code to have the script touch a file, does the modification time of the file indicate whether or not the script is running?

Another thing to try is a simpler script. Save the following in (eg) public_html/test/periodic.php:
Code:
<html>
<body>
<?php
  //header('Content-type: text/plain');

$outf='periodic.html';
$touchf = 'periodic-touch';

$out = fopen($outf, 'w');
$now=date('r');
echo '<p>';
if ($out) {
fwrite($out, <<<EOF
<html>
<body>
	   <h1>{$now}</h1>
</body>
</html>
EOF
	);
    echo "$now written to $outf.";
} else {
	echo "Error opening $outf.";
}
echo '</p><p>', (touch($touchf) ? 'touched' : 'couldn\'t touch'), 
     " $touchf </p>";
?>
</body>
</html>
You can also add code to e-mail you or log extra information in periodic.html.

You'll have to create $touchf and $outf (unless the web user has write access to public_html/test). Schedule periodic.php with:
Code:
*/5 * * * * /usr/local/bin/php /home/pyrokid/public_html/test/periodic.php

Open periodic.php in a web browser to make sure it works, then wait and see if the job runs.
 

cartermcpyro

New Member
Messages
14
Reaction score
0
Points
0
Yes I added that shebang line and it still didn't work.

Also, I don't quite understand what that code you posted does..
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Yes I added that shebang line and it still didn't work.

I was thinking more of the file touch technique. We don't know where the problem lies: (a) maybe cron isn't running the job, (b) maybe cron is trying to run the job but there's something wrong with the command that prevents it running, (c) maybe it's running but failing, or (d) maybe it's just not producing any output. Having the script touch a file is a quick way of telling the last time the script ran.

Also, I don't quite understand what that code you posted does..

It mostly does 2 things: write the time the script runs to peridic.html and touches periodic-touch. Look closely to figure out why (it's not that complex). It's designed to test (a) & (b) above (basic task of programming and debugging: break it down). If periodic.php runs as a cron job, there's probably something wrong with your original script (cases (c) and (d)).
 

kursnalista

New Member
Messages
4
Reaction score
0
Points
0
Hi all!
I follow mission's tutorial, upload the periodic.php and periodic.html files to /home/kurs/public_html/periodic.php, changed the permission 755 for periodic.php and 777 for perodic.html, then made following settings at cron job:
*/10 * * * * /usr/local/bin/php /home/kurs/public_html/periodic.php
I opened periodic.php in a web browser and it works fine, i got these results for periodic.php:

Fri, 10 Apr 2009 02:09:29 -0500 written to periodic.html.

touched periodic-touch

And these for periodic.html:

Fri, 10 Apr 2009 02:09:29 -0500

I dont know why dont work cron jobs for me. What should I do more to solve the problem?
Thank you!

Walter
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I dont know why dont work cron jobs for me. What should I do more to solve the problem?

You know periodic works when run directly. Did you wait until periodic ran as a cron job (which will be when the time is a multiple of ten, like 7:20 or 11:50), then check the contents of periodic.html? Note: don't open periodic.php again. If periodic.html has a time in the last 10 minutes, cron jobs are working for you. If not, there's probably something misconfigured on the server and an admin will need to fix it.
 

woodyl

New Member
Prime Account
Messages
24
Reaction score
0
Points
1
I'm having the same problem; I have not been able to successfully run any cron job or get any email, or indication of what's going on. I also created your "periodic" file and it doesn't work for me, either. I can't figure out what's going on. I'm on the chopin server, BTW.

Guess I'll put in a trouble ticket.
Edit:
I have another question about cron jobs: I understand that I should be able to run php scripts. Is it also possible to run standard *nix commands in a cron job? For instance, can I just issue the linux "touch" command directly from a cron job?
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I'm having the same problem; I have not been able to successfully run any cron job or get any email, or indication of what's going on. I also created your "periodic" file and it doesn't work for me, either. I can't figure out what's going on. I'm on the chopin server, BTW.

Guess I'll put in a trouble ticket.

Just make sure you're testing that the script runs from both the browser and as a cron job.

Edit:
I have another question about cron jobs: I understand that I should be able to run php scripts. Is it also possible to run standard *nix commands in a cron job? For instance, can I just issue the linux "touch" command directly from a cron job?

Unless cron has been limited for security reasons, you can run any command you can otherwise run. The job will run with your credentials. Normal path restrictions apply (the path in cron's environment is rather limited), so you might need to specify the full path to the executable.

kursnalista and woodyl, are your sites using basic or intermediate PHP?
 

woodyl

New Member
Prime Account
Messages
24
Reaction score
0
Points
1
I don't know if I'm using basic or intermediate php. How can I tell. Does that make a difference?

Also:

1. In addition to trying to launch a php script from a cron job, I also issued a direct 'touch' command, which also did nothing.

2. If you run a cron job and it fails because of a script problem, do you still get an email indicating that the job was attempted? Because I'm getting nothing sent to the email address I specified in the crontab. I've tried both email addresses on the site and also an external one and I haven't received any email at all.
 

cartermcpyro

New Member
Messages
14
Reaction score
0
Points
0
2. If you run a cron job and it fails because of a script problem, do you still get an email indicating that the job was attempted? Because I'm getting nothing sent to the email address I specified in the crontab. I've tried both email addresses on the site and also an external one and I haven't received any email at all.
Same problem as me. I think something is just wrong with the cron page.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I don't know if I'm using basic or intermediate php. How can I tell. Does that make a difference?

You have to request an upgrade from basic to intermediate. If you don't know, you're probably using basic. To check, log in to your x10 account (not forum account and not cPanel). Your account page has a field that says which version of PHP your site is using (though this may not be accurate) and a link to request a PHP version upgrade.

PHP version probably won't make a difference with scheduling the script (the restrictions placed on basic PHP will be in place whether run directly or from a cron job), unless the admins have enabled other security restrictions along with the basic build of PHP. It will make a difference in what functions your script can access.

2. If you run a cron job and it fails because of a script problem, do you still get an email indicating that the job was attempted?

If the job produces output, it should send an e-mail. No output, no e-mail. If there's a problem with the command line, there probably won't be any output and hence no e-mail. If the command starts but fails and produces an error message, you should get an e-mail.

Because I'm getting nothing sent to the email address I specified in the crontab. I've tried both email addresses on the site and also an external one and I haven't received any email at all.

I haven't received e-mails sent to an x10hosting mailbox, but have received e-mails sent to a gmail account.

I'm on absolut, using intermediate PHP.
 
Status
Not open for further replies.
Top