Page 1 of 1

Crontab problem, anyone?

Posted: Mon Nov 25, 2002 11:13 am
by JPlush76
Hey all, I'm trying to make a new cron file. Right now its just a simple file to add to the database just so I can test it out.

I created a text file with only

Code: Select all

*/2 * * * * /usr/local/apache/htdocs/temp/testcron.php


and I save that as crontest.txt

I want it to run every two minutes so I can test it quickly for now.

I open up my command line on the unix box running FreeBSD and type in crontab crontest.txt

Then I type in crontab -l and I see my cron job come up.

I set the permissions on the testcron.php file to 777 and added this at the top of the script:

#!/usr/local/bin/php

Its just not running. Any ideas as to why? I thought I followed all the steps. Thanks!

Posted: Mon Nov 25, 2002 11:14 am
by JPlush76
also, when I call that php page directly from my browser it updates the database ok. So I know the code works, the cron job just isn't going :(

Posted: Mon Nov 25, 2002 11:26 am
by kcomer
what does the script do when run from the command line directly, not through cron?

Posted: Mon Nov 25, 2002 11:31 am
by JPlush76
it works fine when I run it from the command line

it inserts one row into my database

here is what my page code looks like:

Code: Select all

#!/usr/local/bin/php
<?php


//***** MAKE DATABASE CONNECTION
$dbhost = 'localhost'; 
$dbuname = 'test';
$dbpass = 'test';   
$dbname = 'dev'; 

function dbconnect() 
&#123; 
 global $dbhost, $dbuname, $dbpass, $dbname; 
 mysql_connect($dbhost, $dbuname, $dbpass); 
 @mysql_select_db($dbname) or die ("Unable to select database"); 
&#125; 

//***** QUERY MYSQL RESULTS
function query_db($query) 
&#123; 
 dbconnect(); 
 return @mysql_query($query); 
&#125; 

$result = query_db("INSERT INTO x_sur VALUES ('test')");
?>

Re: Crontab problem, anyone?

Posted: Mon Nov 25, 2002 11:38 am
by kcomer
Try somthing like this

Code: Select all

*/2 * * * * lynx --dump http://mysite.com/testcron.php > /dev/null
This is how I usually run my cron jobs, beucase I don't have php compiled for command line interface.

Posted: Mon Nov 25, 2002 11:57 am
by JPlush76
nope that didn't work either :(

Posted: Mon Nov 25, 2002 12:05 pm
by kcomer
I'm out of ideas. Throw in some echo commands here and there, run it from the command line and see how far its getting in the script. Print the query or something like that. Print mysql result ids, etc. That's what i'd do.

Posted: Mon Nov 25, 2002 12:55 pm
by JPlush76
well I got it working

it looks like it didn't like the fact I was using a separate file to make the cron job

when I did crontab -e and used the VI editor to enter it in, it seem to have taken it ok.

thanks all!

Posted: Mon Nov 25, 2002 1:14 pm
by BDKR
Did you type in
crontab crontest.txt
?

That's what actually reads a file and it's commands into cron.

Cheers,
BDKR

Posted: Mon Nov 25, 2002 1:15 pm
by JPlush76
yea I did that

but I guess it didnt like it. Maybe I had a bad return carriage or something