Jump to content

Cron Job Help


Recommended Posts

I'm trying to generate a cron job to run the below script, but can't get it to work for the life of me.

 

#!/usr/local/bin/php -q
<?php
if($_GET['key']=="a"){

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$sql="SELECT * FROM $tbl_name3 WHERE review_show='n'";
$result=mysql_query($sql);
$num_results=mysql_num_rows($result);
if($num_results > 0){
if($num_results==1){
$message="You have ".$num_results." review unapproved.";
}
else{
$message="You have ".$num_results." reviews unapproved.";
}
mail('[email protected]','GHP Reviews', $message, 'From: [email protected]');
}

$sql2="SELECT * FROM $tbl_name4 WHERE rma_issued='n'";
$result2=mysql_query($sql2);
$num_results2=mysql_num_rows($result2);
if($num_results2 > 0){
if($num_results2==1){
$message="You have ".$num_results2." RMA Number Requested.";
}
else{
$message="You have ".$num_results2." RMA Numbers Requested.";
}
mail('[email protected]','GHP RMA Number Requests', $message, 'From: [email protected]');
}
echo "Emails Sent.";
}
?>

 

 

Cron Job Command:

php -f /home/zyquo/public_html/ghosthuntersportal.com/cj_run.php?key=a

 

I set the time to run every minute, just to try to get this to work... And in the end I get no emails in my inbox.

Link to comment
https://forums.phpfreaks.com/topic/238007-cron-job-help/
Share on other sites

Hello,

 

 

Try adding this to the end of your commands.

 

 

$result=mysql_query($sql) or mail('[email protected]','ERROR', mysql_error(), 'From: [email protected]');

 

 

This will let you know of any errors in a mysql query. I have done this on a background task and it helped  a lot.

 

 

Have you tried accessing the script via its URL to see if there are any errors?

 

 

George

Link to comment
https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222962
Share on other sites

Hmm Okay,

 

 

Who is your hosting provider?

 

 

I would ask them for some advice. Different systems require configuration in many different ways.

 

 

George

 

I actually have been, they're been trying to help me through it, but I haven't been able to have luck with it.

Link to comment
https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222975
Share on other sites

Have you ran other php scripts in cron on your server successfully using the syntax you have shown?  If not, you might try this....

 

In your crontab: (make sure the path to your script is correct and the script has the correct permissions)

 

*/5 * * * * php -q /CORRECT path to script/cj_run.php?key=a

 

In the script itself, at least on my servers, I don't use the BASH at the top of the php script.  But like I said, if this has worked in the past, leave it.

Link to comment
https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222976
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.