crontab?
I'm talking about a container environments
Both envs and cron python scripts run on root user
Depends. How do you access the env var in cli?
MONGO_CONNECTION = os.getenv('MONGO') And in cli env will return list
That's in Python
Try logging this
This returns None when run as a cron and mongo-svc when run manually print(os.getenv('MONGO'))
Like the values of it?
Maybe the cron isn't taking the env variables
Yes, and I want to know what is the reason and how to solve
What's your cron job command at the moment?
* * * * * /usr/local/bin/python /app/test.py >> /var/log/test.log 2>&1
And if you run something like this manually /usr/local/bin/python /app/test.py >> /var/log/test.log you can see the values of the print(os.getenv('MONGO'))?
I did it once manually and you can see the output
Try changing your print to print(f"{os.getenv('MONGO') = }")
https://ypereirareis.github.io/blog/2016/02/29/docker-crontab-environment-variables/
Why it should differ?
Source the env variables into the cron tab as per the article
Обсуждают сегодня