2

I am trying to implement cron job to write a log file with 1min interval. I have an issue while doing the same. I notice that cron job is not running automatically.

Each time when I run "PHP bin/Magento cron: run " then only cron job gets executed and the database gets populated. If each time I need to run that command then it does not serve as the purpose of corn job.

I follow this link to implement:

https://devdocs.magento.com/guides/v2.2/config-guide/cron/custom-cron-tut.html

Please help me for the same

7
  • have you configured cron in crontab?
    – kunj
    Aug 2, 2018 at 11:53
  • Yes I did it.I made crontab.xml in "etc" and .php in the Cron folder Aug 2, 2018 at 11:58
  • Did you manage to fix it?
    – Raül
    Aug 2, 2018 at 12:13
  • @RaülVila I am executing the command that you mentioned below Aug 2, 2018 at 12:14
  • I typed crontab -e but I dont see anything inside it Aug 2, 2018 at 12:23

2 Answers 2

2

Try this:

just run this command in terminal crontab -e then paste below code in terminal.

* * * * * <path to php binary> <magento install dir>/bin/magento cron:run 

After pasting that code press CTRL + X key then you will see this message.

Save modified buffer (ANSWERING "No" WILL DESTROY CHANGES) ?

Now press Y now you will see this type of message.

File Name to Write: /tmp/{{you will see temp name}}/crontab Just press ENTER And cron set.

It will call every minute Magento cron and Magento will manage your extension's cron and run as per configured time.

After cron configuration you just need to flush the cache.

7
  • Welcome happy to help you
    – kunj
    Aug 2, 2018 at 12:48
  • I have another query. In php file I extend \Psr\Log\LoggerInterface.Is it possible to do some other task not related to log? Aug 3, 2018 at 6:16
  • not getting you.
    – kunj
    Aug 3, 2018 at 6:17
  • I mean to say, I have a Logegr.php file which has a execute method and this execute method runs each time when cron run and write some "hello" in system.log file.And this .php file is same as mentioned in magento devdocs.Now I want to do some other task like log cleaning. Aug 3, 2018 at 6:23
  • yes you can write your custom method at method="execute" and create same method in your php file.
    – kunj
    Aug 3, 2018 at 8:43
1

Make sure all the paths are properly written and there are no extra spaces or anything like that:

In the CLI type: crontab -e and you should see your crons:

* * * * * <path to php binary> <magento install dir>/bin/magento cron:run | grep -v "Ran jobs by schedule" >> <magento install dir>/var/log/magento.cron.log
* * * * * <path to php binary> <magento install dir>/update/cron.php >> <magento install dir>/var/log/update.cron.log
* * * * * <path to php binary> <magento install dir>/bin/magento setup:cron:run >> <magento install dir>/var/log/setup.cron.log

You can run:

php bin/magento setup:upgrade
php bin/magento index:reindex
php bin/magento cache:flush
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.