Re: Environment variables ignored in shells forked within a su sh ell

From: Klaus Oberle (Klaus.Oberle@LINDE-MH.DE)
Date: Wed Feb 26 2003 - 02:40:42 EST


Jorge,

No. What Bill meant is, that you should call your alternate profile from
your "trigger-process":

Your trigger-process (assumed that it is a shellsript!) should begin with

   #!/bin/ksh
   . alternate_profile
   <rest of your trigger CODE here>

Then execute "su user -c trigger-process"

If trigger-process is an executable, you must enclose it together with your
alternate_profile in a third file eg. "start_trigger.sh":

   #!/bin/ksh
   . alternate_profile
   <NAME of your trigger-process here>

and execute "su user -c start_trigger.sh"

/klaus

---------------------------------------------------
Klaus Oberle
IT Administration
Linde Material Handling
Aschaffenburg / Germany
klaus.oberle@linde-mh.de
www.linde.com
---------------------------------------------------

                      Fernandez Garay
                      Jorge An: aix-l@Princeton.EDU
                      <ferjor@COTO.COM Kopie:
                      .AR> Thema: Re: Environment variables ignored in shells forked within a su sh ell
                      Gesendet von:
                      IBM AIX
                      Discussion List
                      <aix-l@Princeton
                      .EDU>

                      25.02.2003 22:51
                      Bitte antworten
                      an IBM AIX
                      Discussion List

Bill:
Tell me if I've missunderstood you.

First, I build a little sh program named, for example
'build_user_env', with the following content:

#!/bin/ksh
. alternate_profile

Given the needed exec permissions, I should exec

su user "-c build_user_env; trigger_process"

The outlined steps above are what you've meant?

I can see the exports executing, with a trace flag,
but 'trigger_process' still fails to get the needed
environment.

If I hardcodes 'trigger_process' within 'alternate_profile',
then it executes OK, because it executes in the same
shell as 'alternate_profile'. In this case, exports
are redundant, for all what is needed is to set the
environment, not to export it.

I'm trying to avoid hardcoding 'trigger_process'
within 'alternate_profile', because, depending on
distinct conditions, 'trigger_process' can be one
of several correcting-actions(each one correspon-
ding to a different condition).

Have I missunderstood you?

Bill, again, thanks for your support.

-----Original Message-----
From: Bill Verzal [mailto:Bill_Verzal@BCBSIL.COM]
Sent: Martes, 25 de Febrero de 2003 07:37 p.m.
To: aix-l@Princeton.EDU
Subject: Re: Environment variables ignored in shells forked within a su
shell

su user
run script, second first line after #!/bin/ksh is ".
<scripttosetenvironment>", where "<scripttosetenvironment>" is your
alternate script.

Variables should be exported.

BV
----------------------------------------------------------------------------

----------------------------
Bill Verzal
Technical Consultant
Forbes Technical Consulting
(312) 653-3684
bill_verzal@bcbsil.com
billverzal@imcingular.com (Pager)
888-428-4025 (Pager)
MailStop: 27.202B

"Fernandez Garay Jorge" <ferjor@COTO.COM.AR>
Sent by: "IBM AIX Discussion List" <aix-l@Princeton.EDU>
02/25/2003 04:56 PM
Please respond to "IBM AIX Discussion List"

        To: aix-l@Princeton.EDU
        cc:
        Subject: Environment variables ignored in shells forked
within a su shell

Within a sh program (is an automated process), I need to su from root
to a user whose .profile is exessively customized for interactive
sessions,
while the automated process runs in the background.

I've tried to avoid this .profile, creating a 'clean', alternate file,
containing
only the indispensable environment needed for the execution of the auto-
mated process.

Next, from this process, I've su'ed to user in the following way:

Having root credentials
su user "-c . alternate_profile; trigger_process". (Note: I'm not
reading
        user's profile)

Where alternate_profile is a file containing environment variables, all of
them exported. Note this file is read, then every line in it, executed,
as
a real .profile.

trigger_process is a process that correct some undesired conditions in
the user's environment, and needs the exported variables to run OK.

Well, problem is that this trigger process can't see the exported envi-
ronment. Within the shell openned by 'su', variables are set.
trigger_process runs in a new shell, and it happened as if all the
exported
environment gets deactivated within the new shell

Has anyone in the list some idea to resolve this problem??
Any help will be appreciated. Thanks in advance.

Jorge

        Ing. Jorge A. Fernandez Garay
                 Administrador UNIX
Jefatura de Tecnologia y Comunicaciones
                    Gerencia de Sistemas

                                             COTO CICSA

**********
The information contained in this communication is confidential, private,
proprietary, or otherwise privileged and is intended only for the use of
the
addressee. Unauthorized use, disclosure, distribution or copying is
strictly prohibited and may be unlawful. If you have received this
communication in error, please notify the sender immediately at
(312)653-6000 in Illinois; (972)766-6900 in Texas; or (800)835-8699 in New
Mexico.
**********

This e-mail may contain confidential and/or privileged information.
If you are not the intended recipient (or have received this e-mail
in error) please notify the sender immediately and destroy this e-mail.
Any unauthorised copying, disclosure or distribution of the material
in this e-mail is strictly forbidden.
Any views expressed in this message are those of the individual
sender, except where the sender specifically states them to be
the views of Linde Material Handling.

Since January 2002 we use the e-mail domain linde-mh.de instead
of linde-fh.de.

This mail has been swept for the presence of computerviruses.



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:37 EDT