When i run my python script from terminal i get error due to missing env variable. i can fix by this using export and setting it. But there are other python scripts that are running fine as cron jobs that require this as well. And i see this env variable being set in cron tab. So my question is if env variable set in cron is available for scripts run by user/root from cli? Running env command as root doesn’t show this variable.
Environment variables are private to each process, not global. When a new process is started it inherits its initial environment from its parent. Your terminal shell isn't started by cron so it doesn't inherit the env vars you've set in your crontab.
Your OS may provide a standard mechanism for setting env vars for all processes (e.g., your terminal which then starts your CLI shell). What I prefer to do is create a file named ~/.environ that I then source in my ~/.bashrc and cron jobs.
python script doesn’t pick up environment variable that is set in crontab