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?
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/