HDFilmMaker2112 Posted May 31, 2011 Share Posted May 31, 2011 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('webmaster@ghosthuntersportal.com','GHP Reviews', $message, 'From: sales@ghosthuntersportal.com'); } $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('webmaster@ghosthuntersportal.com','GHP RMA Number Requests', $message, 'From: sales@ghosthuntersportal.com'); } 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. Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/ Share on other sites More sharing options...
George Botley Posted May 31, 2011 Share Posted May 31, 2011 Hello, Try adding this to the end of your commands. $result=mysql_query($sql) or mail('webmaster@ghosthuntersportal.com','ERROR', mysql_error(), 'From: sales@ghosthuntersportal.com'); 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 Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222962 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 31, 2011 Author Share Posted May 31, 2011 The script runs without a problem when the URL is manually entered. No issues or errors. Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222966 Share on other sites More sharing options...
George Botley Posted May 31, 2011 Share Posted May 31, 2011 Hmm Okay, Who is your hosting provider? I would ask them for some advice. Different systems require configuration in many different ways. George Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222972 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 31, 2011 Author Share Posted May 31, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222975 Share on other sites More sharing options...
dougjohnson Posted May 31, 2011 Share Posted May 31, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222976 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 31, 2011 Author Share Posted May 31, 2011 This is basically the interface I'm working with in CPanel - http://ghosthuntersportal.com/cron.png This is the first time I've tried executing Cron Job. Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222980 Share on other sites More sharing options...
dougjohnson Posted May 31, 2011 Share Posted May 31, 2011 Instead of [?key=a] try: php -f /home/zyquo/public_html/ghosthuntersportal.com/cj_run.php a I don't think you can pass variables the same way in cron as you do from the URL. Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1222989 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 31, 2011 Author Share Posted May 31, 2011 Alright: php -f /home/zyquo/public_html/ghosthuntersportal.com/cj_run.php works... I was hoping to require the ?key=a though so it would block manual access without knowing the value of key. Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1223036 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 31, 2011 Author Share Posted May 31, 2011 I just moved it outside the public_html folder... so now it's impossible to access from outside the server. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1223048 Share on other sites More sharing options...
xyph Posted May 31, 2011 Share Posted May 31, 2011 No query strings allowed in paths. Why not just store the script outside of the web accessible directory. /home/zyquo/cj_run.php Quote Link to comment https://forums.phpfreaks.com/topic/238007-cron-job-help/#findComment-1223051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.