I have been looking at other stack overflow questions but couldn't get any to work. I have a python script which uses environment variables. This script works exactly as planned when run directly however, I would like to run it as a cron job every minute for the time being.
Currently in my cron.d directory I have a file called scrapers containing:
* * * * * root /usr/bin/python3.5 /code/scraper.py
This runs the python script but the script fails as in the script I use two environment variables.
I read I should add SHELL=/bin/bash to the cron file so I did but this didn't help.
SHELL=/bin/bash
* * * * * root /usr/bin/python3.5 /code/scraper.py
Then I read
In the crontab, before you command, add . $HOME/.profile.
SHELL=/bin/bash
* * * * * . $HOME/.profile; root /usr/bin/python3.5 /code/scraper.py
but this caused the cron to stop running altogether. What is the best way of 'sending' the env variables to the cron?
source ~/.bashrc && commandor the file where your env variables are declared and see if it works. - franklinsijoexportcommand to set the variable for that session. - franklinsijo