bash - Unix /Linux - several applications using the same environment variables but different values? -
i looking advice on following below:
i have several applications , tools on server requires environment set variables etc them run.
many of these applications use same environment variables run different values.
some of these applications have multiple versions. e.g. prog v1.1, prog v1.2, prog v1.3 etc..
example:
prog v1.1uses environment variablevar1 = val1,prog v1.2needsvar1 = val2in order run. same variable, different values required each application.another example is:
prog3require number of environment variables setprog4doesn't need.
there logic involved when setting environment these applications, if file exists; this; else that
i've created shell scripts e.g. prog1setup.sh, prog2setup.sh etc setup environment each of these applications , then:
- start new shell every application needs run,
- run shell script ,
- run application inherits environment variables
what i'd know is, there open source tools available out there can used better manage there lots of applications? i've been doing research , came across tools such launcherd, supervisor , environment modules have not used of these before.
if has used of those, please provide insight on if can apply here or there else suggested?
thanks
since mentioned creating scripts, suggest creating prog1.sh with
#!/bin/bash export var1=val1 prog1 "$@" and creating prog2.sh with
#!/bin/bash export var1=val2 prog2 "$@" then, never run prog1 or prog2 directly. instead, run prog1.sh or prog2.sh. since shell scripts environment never affects calling shell, variable var1 exist when needed , disappear once script finishes executing.
alternative
some people prefer functions scripts because function definitions can conveniently stored in ~/.bashrc. examples of functions set needed environment variables:
date2() ( export tz=asia/tokyo; date "$@" ) date3() ( export tz=europe/paris; date "$@" ) these can used follows:
$ date2 wed jul 8 14:49:30 jst 2015 $ date3 wed jul 8 07:49:31 cest 2015
Comments
Post a Comment