hackdaddy has asked for the wisdom of the Perl Monks concerning the following question:

Our application uses a chain of dot .profile configuration files to create the environment variables that numerous ksh shell scripts use. (The .profile sources .profile.abc which sources .profile.xyz, and so on.)

The problem with this approach is that there is not one centralized file where all these configuration settings live. This method of setting the application configuration is causing endless problems. We have inherited this and are looking a "painless" solution due to all the scripts that require environment variables.

One suggestion was to create a ksh function to look up values from a configuration file and to use this function in all assignments in the ksh script. This would bypass having a multitude of environment variables.

Is there a solution where I could use Perl to centralize the configuration settings, but still provide the proper shell environment for older scripts? Right now we must source the .profile chain before running any scripts or middleware from the shell.

  • Comment on Sourcing Dot Profiles for Run-Time Application Configuration

Replies are listed 'Best First'.
Re: Sourcing Dot Profiles for Run-Time Application Configuration
by sauoq (Abbot) on Aug 29, 2002 at 01:22 UTC

    This question, as you posed it, is very difficult to answer.

    You told us very little about what is being done outside of the fact that you are setting up an environment by sourcing shell scripts. You also haven't hinted as to why it is currently done the way it is which may well be important to know.

    What do you mean by the phrase "use Perl to centralize the configuration settings" and what is necessary for a "proper shell environment for older scripts" in your case?

    Generally, trying to use perl to set your environment isn't a great idea. The shell itself excels at it. On the other hand, you might be able to use perl to auto-generate your .profiles from a single centralized config file if they are little more than bunches of variable assignments anyway. Consolidating the logic in that way might be helpful.

    I'm sure if you provide more information someone will be able to provide a more insightful response.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Sourcing Dot Profiles for Run-Time Application Configuration
by peschkaj (Pilgrim) on Aug 29, 2002 at 02:48 UTC
    I tried to conquer this a while ago, and I realized that perl, when doing anything involving the shell, sub-shells and leaves you with squat. You can find a recent discussion: Returning cron. It seems that kshelling is the best way to go on this.
      I recently encountered this problem. I solved it by running (in backticks) the shell script followed by printenv, which prints all the environment variables, and looping through the output setting the environment with %ENV.