AWS Elastic Beanstalk:运行Cron.d脚本,缺少环境变量 [英] AWS Elastic Beanstalk: Running Cron.d script, missing Environment Variables

查看:302
本文介绍了AWS Elastic Beanstalk:运行Cron.d脚本,缺少环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行由cron脚本(在cron.d中)触发的PHP脚本。脚本被正确触发,但缺少存储在$ _SERVER超级全局中的Elastic Beanstalk环境变量。该脚本现在以用户root身份运行,但它不在具有环境变量的同一环境中。变量设置正确,如果我从一个完整的shell运行脚本运行正常。



这些变量的exports在哪里?他们在哪里设置?我在/etc/apache/conf.d/aws_env.conf中找到了SetEnvs for Apache。我在用户的.bashrc,.bash_profile等找不到任何东西。有没有解决方法?



感谢。

解决方案

只是发现这个,使用

  grep -rexport MY_VAR/ 
pre>

编辑:查看文件位置的注释,亚马逊似乎不时移动。



并找到:

  /opt/elasticbeanstalk/support/envvars.d/sysenv 

所以我想在调用我的php脚本之前在我的脚本中包含(source [文件路径]) 。仍然看起来像一个时髦的方式做事情。我仍然在寻找更好的解决方案。



我是通过cron触发的bash脚本运行PHP。所以要设置环境,我会这样做:

 #!/ bin / bash 
source / opt /elasticbeanstalk/support/envvars.d/sysenv
php -f my-script.php

有关PHP解决方案,请参阅下面的@ userid53答案。


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.

解决方案

I just found this, using

grep -r "export MY_VAR" /

EDIT: See the comments for the file location, Amazon seems to move this from time to time.

And found:

/opt/elasticbeanstalk/support/envvars.d/sysenv

So I think I'll just include (source [file path]) that in my script before calling my php script. Still seems like a funky way to do things. I'm still in for better solutions.

I was running PHP via bash script triggered by cron. So to setup the environment, I would do something like this:

#!/bin/bash 
source /opt/elasticbeanstalk/support/envvars.d/sysenv
php -f my-script.php

See @userid53's answer below for PHP solution.

这篇关于AWS Elastic Beanstalk:运行Cron.d脚本,缺少环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆