How to use a common library of environment variables among different languages?
- by JDS
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?