To install/register magento cron jobs to crontab of our envirnoments
we normally use php bin/magento cron:install
, which ends up registering your cronjobs
the system crontab
crontab -l
/var/www/html/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/html/var/log/magento.cron.log
/var/www/html/update/cron.php >> /var/www/html/var/log/update.cron.log
/var/www/html/bin/magento setup:cron:run >> /var/www/html/var/log/setup.cron.log
<type name="Magento\Framework\Crontab\TasksProviderInterface">
<arguments>
<argument name="tasks" xsi:type="array">
<item name="cronMagento" xsi:type="array">
<item name="command" xsi:type="string">{magentoRoot}bin/magento cron:run | grep -v "Ran jobs by schedule" >> {magentoLog}magento.cron.log</item>
</item>
<item name="cronUpdate" xsi:type="array">
<item name="command" xsi:type="string">{magentoRoot}update/cron.php >> {magentoLog}update.cron.log</item>
</item>
<item name="cronSetup" xsi:type="array">
<item name="command" xsi:type="string">{magentoRoot}bin/magento setup:cron:run >> {magentoLog}setup.cron.log</item>
</item>
</argument>
</arguments>
</type>
Sometimes you might need to register you own custom console command which needs to be registered, so we end up adding it to the our own custom xml
<type name="Magento\Framework\Crontab\TasksProviderInterface">
<arguments>
<argument name="tasks" xsi:type="array">
<item name="CUSTOM_CRON" xsi:type="array">
<item name="expression" xsi:type="string">* * * * */15</item>
<item name="command" xsi:type="string">{magentoRoot}bin/magento custom:console:command</item>
</item>
</argument>
</arguments>
</type>