0

I have a Python script for web scraping using Selenium. In that I want to execute the script in a period of time. For that, I want to know how to schedule using crontab on Ubuntu.

Crontab is not opening the browser and executing the Selenium automation, so is there another way to schedule the Python script?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Monic Annadurai
  • 47
  • 1
  • 10

2 Answers2

0

Run command

sudo  crontab -e

If you want to run your script every two hours,

0 */2 * * *  DISPLAY=:0 /usr/bin/python3.7 /home/monic/PycharmProjects/scrap.py

You can adjust the cron schedule from here.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zakaria Shahed
  • 2,589
  • 6
  • 23
  • 52
0

You can use this tool to determine your cron expression.

Do

sudo  crontab -e

Choose the editor if asked nano is easier

Go to the bottom of the file use your cron expression interpretor and path to the python script like this

* * * * * /usr/bin/python /home/myuser/script.py

Above script will run every minute

Explanation

* * * * * is cron-expression 

/usr/bin/python is path to interpretor

/home/myuser/script.py is path to script
Yugandhar Chaudhari
  • 3,831
  • 3
  • 24
  • 40