Cronjob Problem Plzzz Help

Cronjob Problem Plzzz Help

Posted by: ashishtiwari19
Posted on: 2008-01-20 22:44:00

I have a php file that has a simple code to send goodmorning email to a mail id. the file sends goodmorning mail whenever i visit it through web browser. now i want to put it in cronjob so that it sends goodmorning mail every 30 minutes. i have written

30 * * * * /usr/local/bin/php /home/username/domain.com/send.php

as my cronjob entry. yet it is not sending me any mail. i have even added
#!/usr/local/bin/php -q

in my php file. am not getting any error mail also. plz help

Re: Cronjob Problem Plzzz Help

Posted by: sdayman
Posted on: 2008-01-21 06:06:00

That other thread you posted in did have a suggestion to try the following syntax:

/usr/bin/curl -s -o /dev/null http://www.domain.com/send.php


If you're using the panel to enter the cronjob, you don't need the 30 * * * *, so I'm hoping you did this via crontab -e on the command line.

-Scott

Re: Cronjob Problem Plzzz Help

Posted by: ashishtiwari19
Posted on: 2008-01-21 09:12:00

sorry 2 bother u again but am using crontab -e command. i don't have access to anything else. am writing

30 * * * * /usr/bin/curl -s -o /dev/null http://www.ashishtiwari.com/send.php

in my crontab. the file http://www.ashishtiwari.com/send.php works fine when i execute it using browser or using command line but whn i write this in crontab, it is not working. plzzzz help me..

Re: Cronjob Problem Plzzz Help

Posted by: sXi
Posted on: 2008-01-21 10:11:00

30 * * * * curl -s -O http://www.ashishtiwari.com/send.php

Re: Cronjob Problem Plzzz Help

Posted by: ashishtiwari19
Posted on: 2008-01-22 05:35:00

Thanx for the reply but this one also didn't work... what should i do ?

Re: Cronjob Problem Plzzz Help

Posted by: sdayman
Posted on: 2008-01-22 05:54:00

Being nosy, I typed it into my browser and got a "Mission Accomplished" page.

Try:
30 * * * * /usr/bin/curl http://www.ashishtiwari.com/send.php

It may dump results in your mailbox, but at least you'll know it's working. I tried it from command line, and it does work. Make sure to use full path for curl.

-Scott

Re: Cronjob Problem Plzzz Help

Posted by: ashishtiwari19
Posted on: 2008-01-22 06:09:00

thanx 4 the reply, yes i got the mail i.e. output of the send.php as am a beginer , i would be thankfull if you could plz let me know how to find out "full path for curl" ? & am not getting any mails in my mailbox

Re: Cronjob Problem Plzzz Help

Posted by: sdayman
Posted on: 2008-01-22 07:35:00

Full path is /usr/bin/curl
To find out, type 'which curl' on the command line.

-Scott

Re: Cronjob Problem Plzzz Help

Posted by: ashishtiwari19
Posted on: 2008-01-22 08:15:00

Thanx scott for that reply but the problem remains the same now my entry in crontab looks like

30 * * * * /usr/bin/curl http://www.ashishtiwari.com/send.php

but it still won't work. what else can i try ?

Re: Cronjob Problem Plzzz Help

Posted by: digitalvibe
Posted on: 2008-01-22 08:31:00

as suggested futher up the thread, it should be

30 * * * * /usr/bin/curl -s -o /dev/null http://www.ashishtiwari.com/send.php


Alternatively in the panel, go to cron jobs, and enter

/usr/bin/curl -s -o /dev/null http://www.ashishtiwari.com/send.php


If that doesn't work, it's likely to be your code that's broken... try attaching debug vars, catching errors, and emailing the result to yourself via the mail() function (pass or fail with errors).

Cheers,
Karl

web design, development & seo by DigitalVibe

Re: Cronjob Problem Plzzz Help

Posted by: ashishtiwari19
Posted on: 2008-01-22 09:26:00

<?php
$mail = '****@****.com';
$sendto = '*****@****.com';
$msg = "Good Morning";
if(mail($sendto, $subject, $msg, "From: $mail"))
{
echo "Mission Accomplishd";
}
else
{
echo"OOPS Application made a POO POO";
}
?>
this is the code written in send.php file

Re: Cronjob Problem Plzzz Help

Posted by: digitalvibe
Posted on: 2008-01-22 11:12:00

I presume there's more in the send.php file?

- Subject has no value according to that code snippet.

- I meaning that if there was code at work somewhere before it sends the mail, then to trap errors in that block of code and email you a report saying there was a problem.

- An "echo" is useless if you're running a cron job like that because you're never going to see the resulting success/fail message... it needs to mail() you the error.

Cheers,
Karl

web design, development & seo by DigitalVibe

Re: Cronjob Problem Plzzz Help

Posted by: askapache
Posted on: 2008-01-22 14:44:00

http://wiki.dreamhost.com/Crontab

*/30 * * * * /usr/bin/curl -s http://domain.com/send.php 1>&2 &>/dev/null

Re: Cronjob Problem Plzzz Help

Posted by: digitalvibe
Posted on: 2008-01-22 15:52:00

My example should be working already though (i use it on several domains already), which is why i'm suspecting it might be a php code error.

All we know is that "it doesn't work". We don't know any more, so hopefully if the eu can get some sort of debug script together, we can see why it's failing.

Cheers,
Karl

web design, development & seo by DigitalVibe

Re: Cronjob Problem Plzzz Help

Posted by: sXi
Posted on: 2008-01-22 23:45:00

In reply to:

My example should be working already though


I concur. There's nothing wrong with digital's cronjob.


These all work via cron as well:

30 * * * * curl -s -O http://dom.com/path/file.php ~ Will run and NOT bug you with a cron msg mail : See here

30 * * * * curl -s http://dom.com/path/file.php ~ Will run AND WILL bug you with a cron msg mail

30 * * * * curl http://dom.com/path/file.php ~ Will run AND WILL bug you with a cron msg mail


I find /usr/bin/ directives are unnecessary when calling curl.


Re: Cronjob Problem Plzzz Help

Posted by: askapache
Posted on: 2008-01-23 00:35:00

Maybe the problem is occurring because of a bad php configuration or handler on the domain.com, maybe an old php, maybe an old apache 1.3 handler.

execute it directly with php5:

30 * * * * /dh/cgi-system/php5.cgi /home/user/domain.com/send.php 1>&2 &>/dev/null

_____

 _  _|  _  _  _  _|_  _
(_|_|<(_||_)(_|(_| |(/_
|

believe me tis is the only code written in my send.php file & it works fine. am a beginer & would appritiate if you can repair, edit or modify the code of send.php & suggest me the entry in crontab file

Re: Cronjob Problem Plzzz Help

Posted by: sXi
Posted on: 2008-01-23 04:42:00

I used your send.php (with my email address) and inserted this line:

30 * * * * curl -s -O http://www.mydomain.com/send.php

I received an email at 30 minutes after the hour, every hour.

I don't know what else to tell you mate. Maybe you're not waiting long enough to witness the response of the cronjob before considering it failed and changing it? If it's impatience getting in the way, change 30 to */5 for a quicker test result (5 minutes).

Remember to change it back to 30 or */30 later tho.

Re: Cronjob Problem Plzzz Help

Posted by: ashishtiwari19
Posted on: 2008-01-23 07:27:00

30 * * * * /usr/bin/curl -s -o /dev/null http://www.ashishtiwari.com/send.php
30 * * * * /usr/bin/curl -s -O http://www.ashishtiwari.com/path/send.php
30 * * * * /usr/bin/curl -s http://www.ashishtiwari.com/path/send.php
30 * * * * /usr/bin/curl http://www.ashishtiwari.com/path/send.php
30 * * * * curl -s -O http://www.ashishtiwari.com/send.php
30 * * * * /usr/bin/curl -s -O http://www.ashishtiwari.com/send.php

none of them is working. even replacing 30 with 5 is also not working. the crontab entries are given above & the php code am using is given above.

is there any other problem with my setup or any permission is required?

Re: Cronjob Problem Plzzz Help

Posted by: sXi
Posted on: 2008-01-23 07:57:00

I believe you'll need to ask support to take a look at the server config for you. Give them as much information as you can, even link to this thread.

Do let us know how you get on, this is an interesting problem.

Re: Cronjob Problem Plzzz Help

Posted by: digitalvibe
Posted on: 2008-01-23 12:54:00

The problem is, the mail function returns 1 even if you supply duff information to it...

<?
$mail = "****@domain.com";
$sendto = "****@domain.com";
$msg = "Testing email function";

if(mail($sendto, $subject, $msg, "From: $mail"))
{
$log_output = "success";
}
else
{
$log_output = "failed";
}
$hfile = fopen("log.txt", "a");
fwrite($hfile, date("Y-m-d G:i:s")." - $log_output rn");
fclose($hfile);
?>

You will note from that code that the success or failure of the action is stored in "$log_output".

At the end of the script, we open the log.txt file in apend mode - this enables you to add to the end of it.

We create a new row in the log.txt file which has the current server date & time, and the status message.

So, you'll be able to see if the script runs every x minutes. If you see entries coming up in the log file, then it's being fired, so you know you can move on from the crontab line and look at other avenues for the problem.

Cheers,
Karl

web design, development & seo by DigitalVibe