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

From: Fernandez Garay Jorge (ferjor@COTO.COM.AR)
Date: Tue Feb 25 2003 - 20:51:52 EST


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 archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:37 EDT