Cron job failure

Status
Not open for further replies.

woodyl

New Member
Prime Account
Messages
24
Reaction score
0
Points
1
Ok, I'm on php 5.2.9, which, according to some things I've read on the forum, might mean I'm on the intermediate version. Either way, I'm unable to get any output from a php script or even from a direct linux command, e.g., 'touch'. I assume that there are php functions that would work in a cron job even with basic php. For instance, if I create a cron job with a php script that just executes an echo command, I'm getting no output. I assume that an echo command would produce output even with a basic php version.

If I'm wrong about this, please let me know. At this point, I'm looking for any possible means to get a cron job to execute. If I can get past that point, I'll start looking at more complicated scripts.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
I assume that there are php functions that would work in a cron job even with basic php. For instance, if I create a cron job with a php script that just executes an echo command, I'm getting no output. I assume that an echo command would produce output even with a basic php version.

That's right. The limited functions generally deal with system interaction, such as mail(), file() and mysql_*. Output functions work as normal. The PHP upgrade link leads to a page that says "All accounts are set to x10Hosting's PHP v2," which leads me to believe everyone is using at least the intermediate version at this point.

If you want to check whether cPanel is updating your crontab, use the following as a CGI script:
Code:
#!/bin/bash

echo "Content-type: text/plain"
echo

crontab -l

Or the following PHP script:
Code:
<?php
header('Content-type: text/plain');

echo system('crontab -l');
?>

system() is disabled in the basic PHP version (if such a beast still exists), in which case the CGI script should still work.

Here's an updated version of periodic.php. It will record separately the last time it was run from a browser and the last time it was run from cron. It's easier to use but it doesn't tell you anything more than the old one. There's no need to use it if the old one wasn't working, but if anyone wants to test cron, use the newer version. Again, make sure periodic.html exists and is world writable; otherwise, the script may not be able to update periodic.html.
Code:
<?php
header('Content-type: text/plain');

$times = array('cron' => 'never', 'browser' => 'never');
$touchFile = 'periodic-' . $runfrom;
$outf='periodic.html';
$runfrom='cron';
if (isset($_SERVER['HTTP_USER_AGENT'])) {
  $runfrom='browser';
}
echo "Run from $runfrom.\n";


echo (touch($touchFile) ? 'touched' : 'couldn\'t touch'), 
     " $touchFile\n";


$contents = file_get_contents($outf);
if (preg_match('/<p>Previously ran from cron:\s*(.*[^ ])\s*<\/p>/i', $contents, $matches)) {
  $times['cron'] = $matches[1];
}
if (preg_match('/<p>Previously ran from browser:\s*(.*[^ ])\s*<\/p>/i', $contents, $matches)) {
  $times['browser'] = $matches[1];
}
$times[$runfrom]=date('r');

$out = fopen($outf, 'w');
if ($out) {
fwrite($out, <<<EOF
<html>
<body>
<p>Previously ran from cron: {$times['cron']}</p>
<p>Previously ran from browser: {$times['browser']}</p>
</body>
</html>
EOF
	);
    echo "'{$times[$runfrom]}' written to $outf.\n";
} else {
	echo "Error opening $outf.\n";
}
?>
 

kursnalista

New Member
Messages
4
Reaction score
0
Points
0
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.
I waited one day and cron jobs still didnt run for me. There are in the (old) periodic.html the same date when I ran periodic.php file. I will try your new periodic.php, but I am not sure that cron will run for me ever.
Thanks
 

woodyl

New Member
Prime Account
Messages
24
Reaction score
0
Points
1
mission: Thanks for the great suggestions! I've bumped your reputation. Here's what I get from your php script to show the system cron jobs:

MAILTO="wally@yahoo.com"
*/2 * * * * touch /home/wally/etc/cron.test
*/5 * * * * php /home/wally/public_html/cron_test.php
*/5 * * * * php /home/wally/public_html/cron_test.php

(note that, for some reason, the php script repeats the last cron job; there are really only 2 jobs running).

Anyway, your script shows that the jobs should be running, but I'm still seeing no output at all. I've tried some different email addresses, etc., but still nothing.
 
Status
Not open for further replies.
Top