Sample Header Ad - 728x90

Run python code from cron in an Anaconda environment

1 vote
1 answer
4318 views
I need to run a python script using a specific anaconda environment, since I need to execute this script several times per day I would like to do it using the linux crontab file (/etc/crontab). When I launch the script from the linux command line it works fine: ~/anaconda2/envs/py36/bin/python ~/production/web_scraping.py I added the process to the crontab file: SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command 57 08 * * * user ~/anaconda2/envs/py36/bin/python ~/production/web_scraping.py | touch ~/test.txt The line is correctly executed by cron, this is the cron log: user@exmachina:~$ sudo cat /var/log/syslog | grep web_* Jan 2 08:57:02 localhost CRON: (user) CMD (~/anaconda2/envs/py36/bin/python ~/web_scraping.py | touch ~/test.txt) I added | touch test.txt to the cron line to ensure the line is executed, and the *test.txt* file is generated. The python script uses Selenium to extract data from a web page, by means of the chrome webdriver. Can this be the reason the script runs fine from the command line but not from the cron file? Thanks for your help!
Asked by jordi vidal (11 rep)
Jan 2, 2018, 10:42 AM
Last activity: Apr 15, 2025, 02:04 AM