I'm trying to run a python script on a cronjob. To access environment variables in that script, I've wrapped the python script in a short shell script. However, cron does not appear to be accessing my environment correctly, as I'm still getting errors in my python script about not being able to access environment variables. If you consider the below shell script
#!/bin/bash
source /home/jfeldman/.bashrc
env
Running this script from a cronjob yields only this output
SHELL=/bin/sh
PATH=/usr/bin:/bin
PWD=/home/jfeldman
LANG=en_US.UTF-8
SHLVL=1
HOME=/home/jfeldman
LOGNAME=jfeldman
_=/usr/bin/env
Whereas running that shell script from the command line yields a much larger list of environment variables, including the API tokens that I want to access from my python script. Additionally, my PATH variable is considerably shorter than the cronjob version of env
Does anyone know why Cronjobs couldn't access my environment correctly even if the cronjob is running a script that explicitly declares source /home/jfeldman/.bashrc
?
This is the line from the crontab fwiw */5 * * * * /home/jfeldman/crons/test_cron.sh >> /home/jfeldman/crons/test.log 2>&1$`
Edit: after some testing it seems like cron can source my virtual environment just fine, just not .bashrc, which seems incredibly bizarre.
SHELL=/bin/bash
near the top of your crontab.source
isn't throwing an error which suggests that it's not using sh, but something is still going wrong