Cron works, but functionality does not work

I have several PHP files that cron will execute. I installed crons using the command -

crontab crontab.txt 

Inside the crontab.txt file, I wrote cron commands as follows: -

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

But none of the functions work (database queries, sending reminder emails, etc.). Managing URLs is manual.

Then I put my mailing address in MAILTO and received the mail. By mail I received all the HTML code for the page. What is expected in the mail? Why are my functions not working?

Update
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 it comes to 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 at the root of my project, a lot of files index.html.1 , index.html.2 have accumulated. I do not want these files to be created. I just want the files to execute.

The same results if I use one 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 can not use the php command.

I wrote a simple mailto() inside my test.php. Mail does not arrive when it is executed via cron (using both wget and php ), but the URL works manually.

My problem
To clarify again, my main problem is that the functionality inside the cron files is not running. Creating files is a secondary issue.

Any help would be appreciated

Thanks,
Sandeepan

+6
php cron crontab
source share
7 answers

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

When starting manually, I simply entered the test into the URL, a list of saved browser URLs appeared, and I selected the URL http://www.test.project.com/cron/tutor_activities.php , but I put http://test.project.com/cron/tutor_activities.php in the crontab file http://test.project.com/cron/tutor_activities.php . I mistakenly assumed that this would work http://www.test.project.com/cron/tutor_activities.php (because we have a rewrite rule to add www )

But the rewrite rule redirected it to http://www.test.project.com/home . This is why the HTML content is in the letters.

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

+1
source share

if you want to call url as cronjob, you have to use somthing as wget . if it is php-script on your server, it would be easier to use php /...pathtomyscript.../cron/tutor_activities.php

+7
source share

try

which php

The return path must be placed by the command that is passed to run the Cron file. If you configure Cron through the shell, this will not give any problems, but to be sure, try to give an absolute path when you try to run a php page.

/ path / to / php / path / to / cron / script /

Try to give your team so if the problem persists, feel free to discuss.

+7
source share

When you call wget with -O - , it sends the downloaded content to stdout, which cron sends you via email. In the first case, he does exactly what he should.

When you call wget without the -O option, it will try to save the downloaded content as a file with the same name as the loaded web page. If it exists, it will add an increment to the name, as you saw. In this second case, he does exactly what he should.

It is not clear from your question where you want the output to be executed, but if you want to save the output to the same file each time, use -O myfilename.html .

+1
source share

If your executable php from cron / command line doesn't delay the full path to php executable

+1
source share

It is entirely possible that PHP is not in a path inside the cron environment - it will definitely not have the same setup as your regular shell. Try using the absolute path to the BOTH php interpreter AND php script in the cron command:

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

As for creating files, you just need to add a redirect to your wget command:

 wget -O - ... http://.... > /dev/null 

-O - makes wget write everything it downloads to standard output, which will then gladly send you an email. By adding > /dev/null at the end of the command, instead, this output will go to the "Great Bitbucket" in the sky. If you also do not want the output of the wget stderr file to be emailed, you can also add 2&>1 after /dev/null , which then redirects stderr to stdout, which will now be / dev / null.

+1
source share

An easy and safe (without tmp files) way to do this is to use a bash process replacement:

 * * * * * bash -c "/path/to/php <(/usr/bin/wget -O - -q -t 1 http://project/cron/tutor_activities.php)" 

Process substitution executes the command in <() and places the output in an object file, which is visible only from the current process. To use it from cron, call bash directly and pass it as a command line.

As already mentioned, use the full path to php, which you can find out with which php .

0
source share

All Articles