Crontab problem, anyone?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Crontab problem, anyone?

Post 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!
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post 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 :(
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

what does the script do when run from the command line directly, not through cron?
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post 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')");
?>
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Re: Crontab problem, anyone?

Post 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.
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

nope that didn't work either :(
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post 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.
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post 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!
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

Did you type in
crontab crontest.txt
?

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

Cheers,
BDKR
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

yea I did that

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