How to use a common library of environment variables among different languages?
Posted
by
JDS
on Server Fault
See other posts from Server Fault
or by JDS
Published on 2013-07-02T16:01:54Z
Indexed on
2013/07/02
17:07 UTC
Read the original article
Hit count: 227
We have three main languages with which we perform system tasks: Bash, Ruby, and PHP, and Perl. Four, four main languages.
We use managed environment variables to provide authorization info that automated scripts need. For example, a mysql user account and password.
We'd like to use one single managed file to maintain these variables. In some instances, for example, in cron, these environment variables are not available. They are made available in CLI scripts because we source the env file in everyone's profile. But something like cron doesn't do that.
On the CLI, when the env file is sourced, any given script can access those variables. Bash has them directly, PHP in $_ENV, ruby in ENV, etc.
We can't source the file into non-Bash scripts, because most languages implement shell commands by running them in a subshell.
We considered parsing the Bash, converting to the script's lang, and running the equivalent of "exec(parsed_output)" on the resulting strings.
What is a good solution to providing managed environment vars to scripts running in cron, or similar?
© Server Fault or respective owner