<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Set environment variable based on metadata user on GRID in Administration and Deployment</title>
    <link>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695464#M20578</link>
    <description>&lt;P&gt;Hi Greg,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for this piece of code. Now I can remove the part with %mduetr, so this part will run faster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any idea of how I can set the environment variable to be used in my .sh setup file as well? I assume that this code will only create a macro variable that exists within my sas session.&lt;/P&gt;</description>
    <pubDate>Fri, 30 Oct 2020 13:38:29 GMT</pubDate>
    <dc:creator>fkildegaard</dc:creator>
    <dc:date>2020-10-30T13:38:29Z</dc:date>
    <item>
      <title>Set environment variable based on metadata user on GRID</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695223#M20554</link>
      <description>&lt;P&gt;Hi Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a customer that wants to setup a Sandbox in their development environment (In a GRID on Linux (SAS 9.4M6)). This means that each user have their own autoexec and their own sasenv.sh file where they can set their own environment variables. If the user does not have a personal user folder then a common autoexec and sasenv.sh file should be read.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the autoexec, I usually use %sysget('METAUSER') to find the user logged in and this works for other machines in the environment with a Workspace Server, but it seems that there is no METAUSER environment variable set on the machines in the GRID. I have checked the production environment and it seems to be the same case here. You can see how I have verified this if you go to the appendix in the bottom.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So my workaround for the autoexec is to use the %mduextr macro instead. From here I can find the user logged in as well and then I can %include the correct autoexec for the user. It takes a little bit longer time start up, but I can live with that. However, it would be nice, if there is a way to add the METAUSER environment variable to the GRID machines also. Is it possible?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the environment variables I am running a custom .sh file that needs to set the correct environment variables and the code looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if [[ -f "$SANDBOX/$USER/sasenv.sh" ]] ; then
        . $SANDBOX/$USER/sasenv.sh
else . $CURRENT_LEVEL_ROOT/SASApp/sasenv.sh
fi&lt;/PRE&gt;&lt;P&gt;The problem with this code is that $USER resolves to the service account that runs the Workspace Server. It works fine if I create a folder for the service account, but I need to look for the user logged in to metadata. Is there a way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have played around with X commands, %SYSEXEC and the data step statement call system. Because once we get to the SAS Session I can use %mduextr to figure the metadata user out. But it seems that I can not affect the parent process with the new environment variable. Only child processes. So I need to set the variables earlier.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appendix:&lt;/P&gt;&lt;P&gt;When I start a Workspace session on a machine that is not part of the GRID. I can see that an environment variable called METAUSER is set. I find my session ID in Management Console (it could be 32071) and then I run the following code as root:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;strings /proc/32071/environ | grep METAUSER&lt;/PRE&gt;&lt;P&gt;I get the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="metauser.JPG" style="width: 780px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51196iA1DB82C0DF0E2907/image-size/large?v=v2&amp;amp;px=999" role="button" title="metauser.JPG" alt="metauser.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I do the same on one of the GRID machines, I don't get the METAUSER environment variables:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="metauser2.JPG" style="width: 776px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51197i78C11071C0FA5159/image-size/large?v=v2&amp;amp;px=999" role="button" title="metauser2.JPG" alt="metauser2.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And from SAS I also get an note that suggests that the variable is missing:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="metauser3.JPG" style="width: 834px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/51198iE71DC892F6759D37/image-size/large?v=v2&amp;amp;px=999" role="button" title="metauser3.JPG" alt="metauser3.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 15:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695223#M20554</guid>
      <dc:creator>fkildegaard</dc:creator>
      <dc:date>2020-10-29T15:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Set environment variable based on metadata user on GRID</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695240#M20556</link>
      <description>There must be a process that creates the METAUSER environment variable in the dev environment.&lt;BR /&gt;They could be the login scripts.(,bash_profile, .bashrc etc as may be applicable).</description>
      <pubDate>Thu, 29 Oct 2020 15:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695240#M20556</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2020-10-29T15:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: Set environment variable based on metadata user on GRID</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695426#M20572</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I agree. But I haven't been able to find these scripts. Shouldn't be inside the SAS installation or configuration somewhere? I guess that is the only thing that makes sense since METAUSER is coming from SAS Metadata.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If someone can point me to a script that sets the METAUSER environment variable, I will be very grateful&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 10:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695426#M20572</guid>
      <dc:creator>fkildegaard</dc:creator>
      <dc:date>2020-10-30T10:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Set environment variable based on metadata user on GRID</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695461#M20577</link>
      <description>&lt;P&gt;This code would do it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc optsave out=work.options; run;
proc sql;
select OPTVALUE into:metauser from work.options where OPTNAME="METAUSER";
quit;
options set=metauser='&amp;amp;metauser';&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Oct 2020 13:23:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695461#M20577</guid>
      <dc:creator>gwootton</dc:creator>
      <dc:date>2020-10-30T13:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: Set environment variable based on metadata user on GRID</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695464#M20578</link>
      <description>&lt;P&gt;Hi Greg,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for this piece of code. Now I can remove the part with %mduetr, so this part will run faster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have any idea of how I can set the environment variable to be used in my .sh setup file as well? I assume that this code will only create a macro variable that exists within my sas session.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Oct 2020 13:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695464#M20578</guid>
      <dc:creator>fkildegaard</dc:creator>
      <dc:date>2020-10-30T13:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Set environment variable based on metadata user on GRID</title>
      <link>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695494#M20579</link>
      <description>&lt;P&gt;A quick update here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the solution, Greg. I did not see&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options set=METAUSER='&amp;amp;metauser';&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Which set an environment variable on Linux. And the customer has x command enabled, so I can call the sh script from the autoexec after setting the METAUSER variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just one correction. In the options statement the &amp;amp;metauser needs to be enclosed with " " instead of ' ' in order for the value to translate correctly. And then I remove everything else than the username from the OPTVALUE that came from the proc optsave that you showed me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options set=METAUSER="&amp;amp;metauser";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Oct 2020 14:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Administration-and-Deployment/Set-environment-variable-based-on-metadata-user-on-GRID/m-p/695494#M20579</guid>
      <dc:creator>fkildegaard</dc:creator>
      <dc:date>2020-10-30T14:38:07Z</dc:date>
    </item>
  </channel>
</rss>

