I have made one script (addproducts.php) in my Magento root folder for adding products programmatically. For now, I am hitting this script in URL as localhost/addproducts.php. What should I do to execute this script through cron job. How can I set this script to run at regular time interval?

  • You can create Magento 2 module, then create Cron method and set that on crontab. Or you can directly set your script to cron through cpanel (crons) or if you have shell access then run crontab -e then you will get an editor where you can add your file as well. Commented Feb 5, 2020 at 12:45

2 Answers 2


There are 2 ways to execute that script.

First Method: Set cron job in server cPanel. You can follow below link to do this.


Second Method: Create custom module to set cron job and execute your script. check below link for your help.


Note: second method is highly recommended.


You can do this by using server hosting cPanel 'Add cron job' feature by specifying script file url and time of execution.

Also you can do this by creating a cron job using a module. For reference follow this link https://www.mageplaza.com/devdocs/magento-2-create-cron-job/

Your Answer

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

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