Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Elastic Beanstalk: Running Cron.d script, missing Environment Variables

I'm trying to run a PHP script that is triggered by a cron script (in cron.d). The script is triggered properly but it is missing the Elastic Beanstalk "Environment Variables" that are stored in the $_SERVER superglobal. The script is being run as the user "root" for now, but it's not in the same environment that has the environment variables. The variables are set correctly, if I run the script from a full shell it runs just fine.

Where are the "exports" for these variables? Where do they get set? I found the SetEnvs for Apache in /etc/apache/conf.d/aws_env.conf. I can't find anything in the user's .bashrc, .bash_profile, etc. Is there a workaround? A better way to do this?

Thanks.

like image 235
four43 Avatar asked Mar 21 '14 16:03

four43


People also ask

Does crontab have access to environment variables?

You can define environment variables in the crontab itself when running crontab -e from the command line.

What environment does Cron run in?

The default environment for a cron job consists of /etc/environment, and the default shell environment variables such as $PATH, $HOME and $PWD. Information in login files (for example, /etc/profile, ~/. profile, and ~/. kshrc, so it is unlikely $PATH contains login shell directories.


1 Answers

While searching for solutions to the same problem I ran into this blog post: http://sebgoo.blogspot.nl/2013/10/elastic-beanstalk-cron-command-and-rds.html. To summarize, you can load the Elastic Beanstalk environment variables using the opt/elasticbeanstalk/support/envvars file:

0 3 * * * . /opt/elasticbeanstalk/support/envvars; some_command

Hope this helps!

like image 132
Elte Hupkes Avatar answered Sep 28 '22 03:09

Elte Hupkes