2

I'm newbie making cronjobs with linux. My goal is to execute a python script in its own virtual enviroment.

To do this I have made first a shell script called twitter.sh where its content is:

source /home/josecarlos/Workspace/python/robot2-rss/venv/bin/activate 
python /home/josecarlos/Workspace/python/robot2-rss/main.py R,1

And its route is:

/home/josecarlos/Workspace/python/robot2-rss

We have access to source and python commands due their routes /usr/bin are included in the PATH variable as you can see in the next image:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin

The config of my cronjob is:

# m h  dom mon dow   command
*/1 * * * * /home/josecarlos/Workspace/python/robot2-rss/twitter.sh

However, this configuration of my cron job doesn't works and I don't know what am I doing wrong :(

Edit I:

I have modified my twitter.sh script to this new code:

#!/bin/sh

/home/josecarlos/Workspace/python/robot2-rss/venv/bin/python /home/josecarlos/Workspace/python/robot2-rss/main.py R,1

If I run the script directly works fine but with the cron job doesn't work!!! :(

Edit II:

How in the last modification from twitter.sh I just only was calling to my python script, I have modified my cron job to call directly to the python script like this:

# m h  dom mon dow   command
* * * * * /home/josecarlos/Workspace/python/robot2-rss/venv/bin/python /home/josecarlos/Workspace/python/robot2-rss/main.py R,1

And it doesn't work :( I don't know what happen :(

1
  • Could you replace the images with text? Not everybody, and not every software tool, can read pictures. Commented Jul 7, 2021 at 0:34

1 Answer 1

3

set a proper shell

edit twitter.sh

#!/bin/bash
PATH=....
source /home/josecarlos/Workspace/python/robot2-rss/venv/bin/activate 
python /home/josecarlos/Workspace/python/robot2-rss/main.py R,1

be sure to set PATH.

log result of command

in crontab add login part

*/1 * * * * /home/josecarlos/Workspace/python/robot2-rss/twitter.sh >> /var/log/twitter.log 2>&1

if something goes wrong, you can have a look at /var/log/twitter.log

3
  • Thanks @Archemar!!! Your solution has help me a lot!!! Commented Jul 7, 2021 at 10:49
  • 1
    where should we set PATH to?
    – Fayaz
    Commented Mar 28, 2023 at 10:04
  • @Fayaz this depend completly on your context
    – Archemar
    Commented Mar 28, 2023 at 13:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .