11 Replies Latest reply: Jan 19, 2005 2:58 PM by Diane Graves RSS

setting environment for OS processes

Vladimir Tsichevski

Hi,

I need to run external OS command from PSL code. Also, I need to set environment variables for that command at runtime.

I read somewhere that the "environment" instance variable can do the trick. Indeed, if I do

set&#40;&quot;/MyApp/MyInst/environment&quot;, &quot;a=b;c=d&quot;&#41;;<br /><br />print&#40;&quot;a=&lt;&quot;, execute&#40;&quot;OS&quot;, &quot;/bin/echo $a&quot;&#41;, &quot;&gt;\n&quot;&#41;;



I get

a=&lt;b;c=d<br />&gt;



i.e. all text following the first equal sign was assigned to the `a' environment variable.

Does anyone knows is it a bug or a feature?

  • 1. RE: setting environment for OS processes
    DevConGuest NameToUpdate

    This is the default behavior of the OS "set" command.

    Try this from a command prompt in Windows:

    comands:
    set a=b;c=d
    echo %a%
    results:
    b;c=d
    Every character on the left side of the 1st equals sign, "=", is the variable, in your case "a" and every thing on the right side of the 1st equals sign, "=", is that string being set, in your case "b;c=d". Thus the variable "a" results in the string "b;c=d".

    For more info, from the command prompt in Windows execute "set /?".

    To get the behavior that you want try this

    set&#40;&quot;/MyApp/MyInst/environment&quot;, &quot;MyVar=a=b;c=d&quot;&#41;; <br />print&#40;&quot;a=&lt;&quot;, execute&#40;&quot;OS&quot;, &quot;/bin/echo $MyVar&quot;&#41;, &quot;&gt;\n&quot;&#41;; 


    Regards, Bob

  • 2. Re: RE: setting environment for OS processes
    Vladimir Tsichevski

    Thanks, Bob, for prompt reply

    "This is the default behavior of the OS "set" command.
    "

    I work on Linux and Solaris. I haven't tried it on Windows

    "To get the behavior that you want try this

    set&#40;&quot;/MyApp/MyInst/environment&quot;, &quot;MyVar=a=b;c=d&quot;&#41;; <br />print&#40;&quot;a=&lt;&quot;, execute&#40;&quot;OS&quot;, &quot;/bin/echo $MyVar&quot;&#41;, &quot;&gt;\n&quot;&#41;; 


    Regards, Bob"

    I'm not a Windows guru, which names are set in "MyVar=a=b;c=d" ?
    I wanted to set `a' to `b', and `c' to `d'.

    BTW, as result of new experiment I learned that comma (instead of semicolon) may be used to delimit variable declarations.
    I still anger to get a reference to the docs, or at least to get an official answer from BMC people

  • 3.
    msharpe

    In the original post, using a comma as the delimiter instead of a semi-colon should set the environment variable as you would like.

  • 4.
    Laurent Hemeryck

    Hi,

    Depending on what you want to do, wouldn't it be easier if you type in the environment variables directly in the properties of the parameter ?
    You may also edit the "environment" variable, directly under the parameter.

    All the OS commands launched from this parameter will inherit those environment variables.

    Kind regards,

  • 5.
    Vladimir Tsichevski

    "Hi,

    Depending on what you want to do, wouldn't it be easier if you type in the environment variables directly in the properties of the parameter ?
    You may also edit the "environment" variable, directly under the parameter.

    All the OS commands launched from this parameter will inherit those environment variables.

    Kind regards,"

    This is the way I do now. Since I learned that I can use macros in the ENVIRONMENT definition in KM, so I can assign real values at runtime

  • 6.
    Laurent Hemeryck

    "This is the way I do now. Since I learned that I can use macros in the ENVIRONMENT definition in KM, so I can assign real values at runtime"

    Hi tsichevski,

    What do you mean with macros in the environment variables ? Could you please show us an example ?

    TIA,

  • 7.
    Vladimir Tsichevski

    "[quote:65cc098001="tsichevski"]This is the way I do now. Since I learned that I can use macros in the ENVIRONMENT definition in KM, so I can assign real values at runtime"

    Hi tsichevski,

    What do you mean with macros in the environment variables ? Could you please show us an example ?

    TIA,[/quote:65cc098001]

    Here is an example from KMs for ORACLE:

    ENVIRONMENT = &#123;  &quot;%&#123;ld_library_name&#125;&quot; = &quot;%&#123;ld_library_path&#125;&quot;,<br />  &quot;%&#123;remote_connect&#125;&quot; = &quot;%&#123;tns_name&#125;&quot;,<br />  &quot;%&#123;sid_name&#125;&quot; = &quot;%&#123;oracle_sid&#125;&quot;,<br />  &quot;ORACLE_HOME&quot; = &quot;%&#123;oracle_home&#125;&quot; &#125;,



    As you may see, macros are used both for names and values.

    In runtime, macro values are read from object (instance or parameter) variables. Use PSL `set' function to provide values.

  • 8. RE: setting environment for OS processes
    Diane Graves

    "Here is an example from KMs for ORACLE:

    ENVIRONMENT = &#123;  &quot;%&#123;ld_library_name&#125;&quot; = &quot;%&#123;ld_library_path&#125;&quot;,<br />  &quot;%&#123;remote_connect&#125;&quot; = &quot;%&#123;tns_name&#125;&quot;,<br />  &quot;%&#123;sid_name&#125;&quot; = &quot;%&#123;oracle_sid&#125;&quot;,<br />  &quot;ORACLE_HOME&quot; = &quot;%&#123;oracle_home&#125;&quot; &#125;,



    As you may see, macros are used both for names and values.

    In runtime, macro values are read from object (instance or parameter) variables. Use PSL `set' function to provide values."

    I have been able to successfully use macros and the ENVIRONMENT setting for commands run from parameter scripts. What about KM discovery and pre-discovery scripts? How can I define ENVIRONMENT for these?

    I am dealing with a critical need to use the $LIBPATH variable on AIX, which precludes the use of the userrc.sh file to store Unix shell environment variables. The commands requiring these $LIBPATH entries are executed in both discovery and parameter command scripts.

    Is there any way to set this ENVIRONMENT variable at a global level for the KM?

  • 9. RE: setting environment for OS processes
    Susan Miller

    You need to define the enviroment variable at the OS KM. Go to ALL_COMPUTERS, expand and then locate the local folder. Under the folder select the appropriate operating system and then add the enviroment variable. The application class KMs all inherit from these KM. If you only have one OS type you can do it from ALL_COMPUTERS under the global folder.

  • 10. RE: setting environment for OS processes
    Vladimir Tsichevski

    "You need to define the enviroment variable at the OS KM. Go to ALL_COMPUTERS, expand and then locate the local folder. Under the folder select the appropriate operating system and then add the enviroment variable. The application class KMs all inherit from these KM. If you only have one OS type you can do it from ALL_COMPUTERS under the global folder."

    IMHO, more convenient solution would be to add directives affecting the "computer class" environment to the "application" KM file. For example, the following KM text defines an application named Test and adds one OS environment variable named "QQQ" to the Linux computer type. The Test application pre-discovery script prints the resulting environment to console system output window.


    Regards,

    Vladimir


    !PATROLV3.4.11 D3782E116951C7D4<br />!#MSG_DOMAIN     unix_kmsec<br />!++<br />!<br />! PATROL Session Knowledge Module<br />!<br />!--<br /><br />VERSION 1.0<br /><br /><br />COMPUTERS = &#123;<br />  &#123;<br />    NAME = &quot;Linux&quot;,<br />    ENVIRONMENT = &#123;<br />      &quot;QQQ&quot; = &quot;WWW&quot;<br />    &#125;<br />  &#125;<br />&#125;<br />APPLICATIONS = &#123;<br />  &#123;<br />    NAME = &quot;Test&quot;,<br />    ACTIVE = True,<br />    SECURITY = False,<br />    PROPAGATE_STATE = True,<br />    CREATE_ICON = True,<br />    SUSPEND_GLOBAL_PARAMS = False,<br />    SHOWINST = False,<br />    DISCOVERY_TIME = 0,<br />    DISCOVERY = PSL,<br />    PRE_DISCOVERY_TEXT = 825639896 &quot;set&#40;active, 2&#41;; print&#40;\&quot;env&#58; \&quot;. system&#40;\&quot;env;\&quot;&#41;&#41;;&quot;,<br />    DISCOVERY_TEXT = 825639896 &quot;exit;&quot;<br />  &#125;<br />&#125;<br />! 9999<br />

     

  • 11. RE: setting environment for OS processes
    Diane Graves

    Thanks Vladimir, this looks like a more workable solution. I'd rather keep all of my KMs needed environment variables self-contained.