I have several PHP files to be run by cron. I set up the crons using command-

crontab crontab.txt

Inside the crontab.txt file, I have written cron commands like this:-

#(Updating tutor activities) - every minute
* * * * * /usr/bin/wget -O - -q -t 1 http://project/cron/tutor_activities.php

But none of the functionalities are working (database queries, sending reminder mails etc.). Running the URLs manually works.

Then I put my mail address in MAILTO and received the mails. In the mail, I received entire HTML source of the page. What is expected in the mail? Why are my functionalities not working?

Updates
If I change my cron commands to

 #(Updating tutor activities) - every minute
    * * * * * /usr/bin/wget http://project/cron/tutor_activities.php

Still no success and this comes in my mail -

--15:03:01--  http://project/cron/tutor_activities.php
          => `tutor_activities.php'
Resolving project... IP Address
Connecting to test.project|IP Address|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: http://project./ [following]
--15:03:01--  http://project./
          => `index.html.1'
Resolving project.... IP Address
Connecting to project.|IP Address|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://project/home/ [following]
--15:03:01--  http://project/home/
          => `index.html.1'
Resolving project... IP Address
Connecting to wproject|IP Address|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
index.html.1 has sprung into existence.
Retrying.

And lots of index.html.1 , index.html.2 files are accumulating in the root of my project. I do not want these files to be created. Just want the files to execute.

Same results if I use either of the two commands -

   * * * * * /usr/bin/wget http://project/cron/tutor_activities.php

   * * * * * wget http://project/cron/tutor_activities.php

running php command with MAILTO set sends me this error /bin/sh: php: command not found.

* * * * * php /path/to/test.php

So, I am not able to use php command.

I have written a simple mailto() inside my test.php. The mail does not come when run through cron (using both wget and php fails) but running the URL manually works.

My problem
To make it clear again, my main problem is that the functionality inside the cron files is not running. Creation of files is a secondary issue.

Any help would be appreciated

Thanks,
Sandeepan

Comments

You don't need to be logged in on your web system to run these queries, send mail, etc., do you?

Written by Matt Gibson

I have found the solution myself. I accept that details of my question were not sufficient enough for anybody to guess the actual reason. But, that itself was the problem. But thank you all for your efforts. I am not manually offering bounty to anyone. Let the votes decide the bounty.

Written by Sandeepan Nath

Accepted Answer

I found the problem myself. I did not put the same URL in my crontab file which I was running manually and that was my mistake.

While running manually I was just typing test in the URL, my browsers's list of saved URLs was appearing and I was selecting the URL http://www.test.project.com/cron/tutor_activities.php, but in the crontab file I had put http://test.project.com/cron/tutor_activities.php. I was mistakenly assuming this would run http://www.test.project.com/cron/tutor_activities.php (because we have a rewrite rule present to add www)

But the rewrite rule was redirecting it to http://www.test.project.com/home. That's why the HTML content in the mails.

So, the most important thing to learn here is to make sure we don't miss the minute things and don't assume that we did everything correctly. In my case, better to copy-paste the working URL into the cron file.

Written by Sandeepan Nath
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki