Search code examples
pythonlinuxcroncron-task

How to make a bash file to run a python script every 2 hours?


I have in an virtualenvironment a python script that I wantt o run every 2 hours using a cronjob

This is my python script:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time



PATH = "/usr/bin/chromedriver"

driver = webdriver.Chrome(PATH)



driver.get("http://bitcoin.works")
driver.maximize_window()
time.sleep(2)
driver.find_element_by_link_text('LOGIN').click()
time.sleep(3)
driver.find_element_by_id("login_form_btc_address").send_keys("MyEmail")
driver.find_element_by_id("login_form_password").send_keys("securePassword")
driver.find_element_by_id("login_button").click()
time.sleep(4)
driver.find_element_by_class_name("pushpad_deny_button").click()
time.sleep(7)
driver.find_element_by_id("free_play_form_button").click()
time.sleep(3)

driver.quit()

I also created a file in my folder named run.sh

that has following content

#!/bin/sh

python run.py

I than did

chmod a+x run.sh

After that i edited my the file under crontab -e

to this

0 */2 * * *  cd Documents/scraping && /bin/bash/ run.sh

why do I need the cd Documents/scraping && /bin/bash/ run.sh line?


Solution

  • Try the following command in the cronjob

    0 */2 * * *   /bin/bash/ ~/Documents/scrapping/run.sh
    

    I think this may help