Magento2 – Cron Job Not Running

cronmagento-2.1.8

I have made all the admin settings based on previous post from magento stack exchange. I have created a custom module to send emails and I want to schedule the email based on cron job. I want to know what is missing. If I run manually the cron job runs successfully and email is sent out. How do I make cron job run in the background so email gets sent out in a scheduled time everyday.

My Admin config settings:

Cron configuration options for group: default

Cron configuration options for group: index

My custom code crontab.xml is as below:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
    <group id="default">
        <job name="Daily_report" instance="Module\Modulename\Cron\sendEmail" method="execute">
            <schedule>*/1 * * * *</schedule>
        </job>
    </group>
</config>

Here is the crontab set-up:

*/1 * * * * www-data php /var/www/html/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log
*/1 * * * * www-data php /var/www/html/magento2/update/cron.php >> /var/www/html/magento2/var/log/update.cron.log
*/1 * * * * www-data php /var/www/html/magento2/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log

UPDATE:

I've updated crontab -e as below:

*/1 * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log
*/1 * * * * /usr/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log
*/1 * * * * /usr/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log

I can see in /var/log/syslog that the cron is running. Below are the details:

Nov 25 12:52:01  CRON[30803]: (ubuntu) CMD (/usr/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log)
Nov 25 12:52:01  CRON[30800]: (CRON) info (No MTA installed, discarding output)
Nov 25 12:52:01 CRON[30804]: (ubuntu) CMD (/usr/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log)
Nov 25 12:52:01 CRON[30805]: (ubuntu) CMD (/usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/mage$
Nov 25 12:52:01  CRON[30801]: (CRON) info (No MTA installed, discarding output)
Nov 25 12:52:02  CRON[30802]: (CRON) info (No MTA installed, discarding output)

However, none of the cron jobs ran. There is nothing in magento log files.

Could you please help me out? I have hosted my test server in AWS Ubuntu server.

Best Answer

first find php path using below command

which php

whatever results come you need replace with php into cron setup

Also add below cron using ubuntu user : crontab -e add below crontab

* * * * * php /var/www/html/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/magento2/var/log/magento.cron.log
* * * * * php /var/www/html/magento2/update/cron.php >> /var/www/html/magento2/var/log/update.cron.log
* * * * * php /var/www/html/magento2/bin/magento setup:cron:run >> /var/www/html/magento2/var/log/setup.cron.log

Remove crontab from root user.

Related Topic