Answer the question
In order to leave comments, you need to log in
How to run python script from cron?
There is a parser written in Python, I'm trying to add it to Cron so that it runs on schedule.
Added the following command to the task:
cd /home/user/parser/ && source venv/bin/activate && /home/user/parser/run.py >> /home/user/parser/run.log 2>&1
Feb 21 12:45:01 mycomp CROND[18202]: (admin) CMD (cd /home/user/parser/ && source venv/bin/activate && /home/user/parser/run.py >> /home/user/parser/run.log 2>&1)
Answer the question
In order to leave comments, you need to log in
My parser works every hour according to this scenario:
1 */1 * * * cd /home/ubuntu/vk_bot/ && python3 main.py
Maybe something is wrong with your paths after activating the environment?
try to add all this in one script myscript.sh
#! /bin/bash
set -ex
cd /home/user/parser/
source venv/bin/activate
python /home/user/parser/run.py >> /home/user/parser/run.log 2>&1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question