View Full Version : How do I test a cron for functionality?
Silverado05
08-20-2007, 08:42 PM
I have set up two crons and the first time I set it up I got emailed an error. So I searched the forums for a way to set it up correctly. Well I think it is set up correctly now because I haven't received any errors emailed, but I also haven't received any emails that it was run successfully. So how can I check to see if it was set up correctly?
-Thanks
silentcollision
08-21-2007, 04:05 AM
Why don't you make it do an additional, small function, such as creating a file, or writing something to a file?
Chances are though, if you've set it to receve an email, and you haven't, it isn't working. Maybe check the path you've set.
Silverado05
08-21-2007, 07:13 PM
Chances are though, if you've set it to receve an email, and you haven't, it isn't working. Maybe check the path you've set.
Oh no I think you have misunderstood. I don't know if you have every set up a cron here or not. But when you set it up you have the option for it to send conformation email or error emails when the cron is actually executed. When I set it up the first time it wasn't set up correctly because I received a error email. Well when I went back to fix it I haven't received an email saying if it is working or not. So I do I know if I have the correct file path and it is actually working? This isn't an email script, the actual cron itself is not suppose to email me. The cron is suppose to automatically run my Google Base and BizRate feeds weekly so I don't have to manually run them everytime I update my catalog.
-Thanks
Maggilove
08-22-2007, 02:49 AM
Sounds like your path could be incorrect. Have you checked your feeds folder to see if the feed has been created? If so, did you check your Google Base and Bizrate accounts to see if the feed was uploaded?
You really should have the script e-mail you the result - I know from my e-mail if my upload was successful and, if not, at which point it failed.
That said, cron here is a little bit odd... support has confirmed that my cron jobs (on two different boxes) are correctly set up to run every three weeks at midnight GMT on a Friday, but they run weekly on Fridays... and occasionally on other days too (for example, I got up this morning to e-mails saying they had been successfully executed). I have tried changing the day and time, which was the only thing support could suggest, but to no avail... if anyone has any ideas I would be grateful, as this has us all flummoxed.
Silverado05
08-22-2007, 11:59 PM
You really should have the script e-mail you the result - I know from my e-mail if my upload was successful and, if not, at which point it failed.
As noted twice in above posts I do have it set up to email me the results. That is why I am here. When I first set it up I received an error email right off the bat that it wasn't set up correctly. So I went back and fixed it and I have not received anything stating that it ran successfully or with errors. So I am not sure if it is right now or not and I don't know how to tell. The feeds it runs are already in a folder so it just overwrites those files with the new one every time it is ran. It is not scheduled to run until Sunday though. I still got an error email though if it wasn't set correctly. Should I not worry about it then since I have not received an email? I sure would like to know if it is set up correctly. So is their another way to check?
intenziti
08-23-2007, 12:43 AM
Hi there,
I came upon this thread while looking for code for a project I am completing for university. I have made a form with a drop down menu so that the user can query the database about which course is available in each month. However I keep getting this error message
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Applications/xampp/xamppfiles/htdocs/paul/month_drop_down.php on line 41
The php code I actually got from this page: http://www.webmasterworld.com/forum88/4831.htm I have tried to adapt it to suit my purposes and it seems that all my database information is correct but for the likes of me I cannot work out why the php code is not processing the form data from the drop down menu.
Would anyone here please be able to have a quick look at my code and see if there is anything that may be stopping it from functioning?
There are two fields in my table which are called 'month' and 'course', the table itself is called months.
Any help would be greatly appreciated!
Form code:
<form name="month_search" method="post" action="month_drop_down.php"><table width="600" align="center" border="0" cellspacing="1" cellpadding="2">
<tr><td width=300><select name="month" id="selCourse" style="width: 200px;"><option value="Select month to attend..." selected>Select month to attend...</option><option value="jan">January</option><option value="feb">February</option><option value="mar">March</option><option value="apr">April</option><option value="may">May</option><option value="jun">June</option><option value="jul">July</option><option value="aug">August</option><option value="sep">September</option><option value="oct">October</option><option value="nov">November</option><option value="dec">December</option></select></td><td><input type="submit" name="search" value="Search"/></td>
</tr>
</table></form>
PHP code:
<?php
// get variable after selecting something from the dropdown with name 'month'
$select = $_POST['search'];
// if something has been chosen
if (!empty($select)) {
// get the chosen value
$month = $_POST['month'];
// select the type from the database
// database connection details (change to whatever you need)
$HOST = 'localhost';
$DATABASE = 'sworphe_paul';
$USER = 'sworphe_paul';
$PASSWORD = 'sworphe_paul';
// connect to database
if(!$conn=mysql_connect('localhost','sworphe_paul' ,'sworphe_paul')) {
echo("<li>Can't connect to $HOST as $USER");
echo("<li>mysql Error: ".mysql_error());
die;
}
// select database
if (!mysql_select_db($DATABASE,$conn)) {
echo("<li>We were unable to select database $DATABASE");
die;
}
// if everything successful create query
// this selects all rows where the type is the one you chose in the dropdown
// * means that it will select all columns, ie name and type as i said above
$sql_query = "SELECT * FROM months WHERE type='$month'";
// get the data from the database
$result = mysql_query($sql_query,$conn);
// output data
while (($deails = mysql_fetch_assoc($result))) {
// print out the name
echo('Courses available in '.$details['month'].' - ');
// print out the type
echo('Type: '.$details['course'].'<br>');
}
// close mysql connection
mysql_close($conn);
}
?>
Thank you so much in advance!
Silverado05
08-23-2007, 12:47 AM
What in the hell does this have to do with a CRON and why are you jacking my thread with a unrelated issue?
You couldn't have started a new thread?
-Thanks
Maggilove
08-23-2007, 04:53 AM
As noted twice in above posts I do have it set up to email me the results. That is why I am here.
OK... sorry, misunderstanding... you said you had set the cron option to send a confirmation e-mail, which is not quite the same as having your script generate an e-mail giving detailed results.
So... what was the error message that you received the first time it executed? What changes did you make? How many times should it have run since then?
If you fire up Unlimited ftp and check the directory info for your feeds folder, you should be able to see when they were last overwritten. As for the path... let's say your script is called feed.php and it sits in a folder in public_html called admin, and your username is silverad... your command would look like this...
/usr/bin/php -q /home/silverad/public_html/admin/feed.php
If your path is correct, I wouldn't worry too much... just wait and see what happens on Sunday.
Silverado05
08-23-2007, 10:27 AM
This is what my command looks like as of now
0 4 * * 3 /usr/local/bin/php -q /$HOME/MYDOMAIN/public_html/admin/googlefeeder.php
Keep in mind, MYDOMAIN is just placed for security.
I can't remember what changes I made. I know one was I changed home to $HOME from other threads I had read. and I added local to the file path. I think that was the only changes.
I don't know exactly what the error said in the email because I opened it on my smart phone and it didn't open the full message and when I opened my outlook it was gone.
I have never set up a cron before and I searched the forum and tried what I had found but wasn't sure if it was correct or not since I wasn't getting any error emails this second time.
-Thanks
Maggilove
08-23-2007, 11:50 AM
My commands are all in this format....
/usr/bin/php -q /home/mydomain/public_html/admin/myfile.php
...and they work just fine.
I should wait until Sunday and see if you get an error message this time.
Silverado05
08-23-2007, 12:04 PM
Ok thank you, If that doesn't work I will try that path with my files.
Can you tell me what php -q is?
Silverado05
08-26-2007, 10:10 PM
Ok well the cron ran today and and it failed. This is the error I got.
/bin/sh: 0: command not found
Here is the path.
0 4 * * 3 /usr/local/bin/php -q /$HOME/MYDOMAIN/public_html/admin/bizrate.php
How should I set this up?
Silverado05
08-27-2007, 12:05 AM
Ok I have it fixed now and running correctly.
-Thanks
Good to see that you got it fixed.
In PHP versions prior to the 5.2 trunk (which is true of all Bluehost's servers), the -q switch indicates "quiet mode" and suppresses output unless there is an error. Traditional CRON jobs pipe standard out to mail which triggers the message to the defined address. If there is nothing sent to standard out, no email is sent. I wonder if those two regular behaviors were causing your problem? You can test my assumption by modifying your cron job to remove the -q switch. Or just simply run your cron in terminal and examine the output from both the quiet and normal variants. For example:
Normal:
# php yourfiletoexecute.php
Quiet Mode:
# php -q yourfiletoexecute.php
--Cade
Klutzys
09-21-2008, 07:52 PM
I asked bluehost what command I needed to run a cron job to import an RSS feed into my blog and this is what they told me to use:
/ramdisk/bin/php5 -q /home1/MYDOMAIN/public_html/path/to/file
And I wasn't sure what they meant with the path/to/file bit so I did it 2 different ways and it still does not import the blogs, what am I doing wrong?
/ramdisk/bin/php5 -q /home1/MYDOMAIN/public_html/path/to/file/wp_SMARTRSSFILE.php
/ramdisk/bin/php5 -q /home1/MYDOMAIN/public_html/wp_SMARTRSSFILE.php
Any ideas and thoughts would be greatly appreciated as BH has not gotten back with me about it and I am sill waiting........ :)
Tammy
felgall
09-21-2008, 08:13 PM
I asked bluehost what command I needed to run a cron job to import an RSS feed into my blog and this is what they told me to use:
/ramdisk/bin/php5 -q /home1/MYDOMAIN/public_html/path/to/file
And I wasn't sure what they meant with the path/to/file bit so I did it 2 different ways and it still does not import the blogs, what am I doing wrong?
/ramdisk/bin/php5 -q /home1/MYDOMAIN/public_html/path/to/file/wp_SMARTRSSFILE.php
/ramdisk/bin/php5 -q /home1/MYDOMAIN/public_html/wp_SMARTRSSFILE.php
Any ideas and thoughts would be greatly appreciated as BH has not gotten back with me about it and I am sill waiting........ :)
Tammy
Assuming that the file to run is in your puvlic_html and not a folder within that then the command will be
/ramdisk/bin/php5 -q /home1/MYDOMAIN/public_html/wp_SMARTRSSFILE.php
wit your account name substituted where it has MYDOMAIN
dkinzer
09-22-2008, 01:39 PM
wit your account name substituted where it has MYDOMAINIt may be less confusing to some to just use the $HOME environment variable. That variable expands to the path to your account's home directory, reducing the likelihood of mistyping, misunderstanding, etc.
/ramdisk/bin/php5 -q $HOME/public_html/wp_SMARTRSSFILE.php
Klutzys
09-22-2008, 07:19 PM
Assuming that the file to run is in your puvlic_html and not a folder within that then the command will be
/ramdisk/bin/php5 -q /home1/MYDOMAIN/public_html/wp_SMARTRSSFILE.php
wit your account name substituted where it has MYDOMAIN
Ah I think I understand now. Although the files are deeper into public_html, so I will put the exact path and see if that works. Thanks a million.
Tam
path/to/file meant just that DUH ME :p
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.