Commands, Magento2, Magento2 Commands

How to setup Cron Jobs Via SSH In Magento 2?

How to setup Cron Jobs Via SSH In Magento 2?

Magento cron job is an important component for correct performance. Magento uses cron jobs for numerous features to schedule activities. It is widely used for running actions that are performed on schedule, such as indexing and caching, sitemap generation, currency rate updates, and many more as well.

Why need Cron Job for Magento 2 ? Cron job use following activities.

  • Catalog Price Rules
  • Newsletters
  • Generating Google Sitemaps
  • Customer Alerts/Notifications (Product Price Change, Product Back in Stock)
  • Automatic updating of currency rates
  • All Magento e-mails (including Order Confirmation and Transactional)

By using SSH, access your server’s SSH using SSH software such as Putty or Bit vise or local Terminal.

To review the running crones, use the command: crontab -l

Magento uses a five value specification for a cron job. The numbers per each * * * * * is as follows:

  • Minute (0-59)
  • Hour (0-23)
  • Day of month (1 – 31)
  • Month (1 – 12)
  • Day of week (0 – 6) (Sunday to Saturday; 7 is also Sunday on some systems)

For more info you can review here.

To add or edit crons, use the following command: crontab -e

Go to the last line and enter the following line :

Ex :

Save the cron with CTRL + X then enter Y to save the changes.

Note : Different editors save commands are different. Here is the for nano editor.

After saving successfully you will see the below message.

cronjob: installing new crontab

How to set cron for caching or indexing ?

You can use below command for this.

It will run every one day at 1 and 2 hour.

🙂 Happy Coding. Keep Liking & Sharing 💻

Tagged , , ,