tags:

views:

56

answers:

1

Hey

I want to create cronjobs that runs every 10 min < time now

and mail me a email with the follow txt.

"deleted orders"

my code looks like this.

MAILTO=”[email protected]”
*/10 * * * * /var/www/php-sites/dlf/cron_jobs.php

I have checked my mails the last 30 min.. and still havent receive any mails. am i doing it wrong ?

+4  A: 

First of all, as I remember php scripts should be executed this way (example for Ubuntu path, not sure about other distros):

/usr/bin/php-cgi /var/www/php-sites/dlf/cron_jobs.php

Also you can save the job output into the file to see the exact reasons of failures, for your job it can look like:

*/10 * * * * /usr/bin/php-cgi /var/www/php-sites/dlf/cron_jobs.php > /tmp/cron.out 2>&1

Check the cron.out contents.

Hope this helps.


EDIT

I did small test and usual Shell way seems to work too. I've created the script phptest.sh (+x) with contents:

#!/usr/bin/php-cgi

echo "It works this way!";

And it seems to work, except one thing. It throws the headers in the stdout, like this:

***@***:~$ ./phptest.sh
X-Powered-By: PHP/5.2.10-2ubuntu6.3
Content-type: text/html

echo "It works this way!";

But I suppose we can get rid of them somehow, if they are a problem.

The only advantage of this is shorter path :)

Sergii
sweet, sweet :-) Thx you very much.. I forgot to install: sudo aptitude install php5-cgi
william
+1, good answer, of course. But isn't cron's default behavior to take the program's stdout output and stuff it into the mail anyway? If this is so, the second part of your suggestion would be unnecessary; in fact, redirecting the output will cause cron not to send mail, right?
Carl Smotricz
@Carl I'm not sure where cron throws the output by default, but I suppose its a /dev/null, so saving into the file is the common way to check it. Redirecting the output will only redirect the output, havent had any problems with scripts using it :)
Sergii
@Sergii: From `man cron` on Ubuntu Linux: "When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists)." What I'm saying is: If you leave off the redirection, cron will pipe the output to mail and the OP will get his mail. If you pipe it into a file, he never gets any mail.
Carl Smotricz
@Carl This is fine clarification, thanks. But I suppose that William needs to execute the script, which (script) sends the email.
Sergii
The script works fine, but it doesn't send an mail. I use the cron_job.php to send an email via. php.
william
BTW, see my edit. Maybe this can be a bit helpful.
Sergii
this looks great @Sergii :o very nice
william