"su -" doesn't set environment from reading user startup file - SGI

This is a discussion on "su -" doesn't set environment from reading user startup file - SGI ; I'm working on an Irix64 6.5 box and trying to execute a command as another user. This is part of testing something for an init script. However, the command: # su - user -c "echo foo is $FOO" doen't work. ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: "su -" doesn't set environment from reading user startup file

  1. "su -" doesn't set environment from reading user startup file

    I'm working on an Irix64 6.5 box and trying to execute a command as
    another user. This is part of testing something for an init script.
    However, the command:

    # su - user -c "echo foo is $FOO"

    doen't work. The user is using /bin/tcsh and the ~user/.cshrc file
    contains:

    setenv FOO /usr/local/foo/

    in fact, I seem to be seeing what is in ROOT's environment!

    # su - user -c "echo home is $HOME"
    home is /
    # echo $HOME
    /

    running su w/o the command leads to the user being logged in and doing
    "echo $FOO" gives the expected directory that was set above.

    What am I doing wrong? Why don't I see the temp environment the su man
    page talks about when using "su -"?

    Quig


  2. Re: "su -" doesn't set environment from reading user startup file

    One correction:

    I was able to fix the $HOME issue by using single quotes instead of
    double quotes:

    # su - user -c 'echo $HOME'
    /home/user

    however, the user's setup file "/home/user/.cshrc" is still not being
    read, so $FOO isn't getting set.

    Quig




    kevin.quigley@gmail.com wrote:
    > I'm working on an Irix64 6.5 box and trying to execute a command as
    > another user. This is part of testing something for an init script.
    > However, the command:
    >
    > # su - user -c "echo foo is $FOO"
    >
    > doen't work. The user is using /bin/tcsh and the ~user/.cshrc file
    > contains:
    >
    > setenv FOO /usr/local/foo/
    >
    > in fact, I seem to be seeing what is in ROOT's environment!
    >
    > # su - user -c "echo home is $HOME"
    > home is /
    > # echo $HOME
    > /
    >
    > running su w/o the command leads to the user being logged in and doing
    > "echo $FOO" gives the expected directory that was set above.
    >
    > What am I doing wrong? Why don't I see the temp environment the su man
    > page talks about when using "su -"?
    >
    > Quig



  3. Re: "su -" doesn't set environment from reading user startup file


    kevin.quigley@gmail.com wrote:

    > # su - user -c 'echo $HOME'
    > /home/user
    >
    > however, the user's setup file "/home/user/.cshrc" is still not being
    > read, so $FOO isn't getting set.


    # su - davea -c 'echo $HOME ; echo $SHELL ; printenv'
    worked for me on IRIX 6.5.29. As root (where I did the su)
    showed root stuff, as me showed my .cshrc data.

    Add $SHELL and printenv to your command and retry.
    davea


  4. Re: "su -" doesn't set environment from reading user startup file

    Actually, this replay from Brent helped solve the problem. There was a
    block testing for $?prompt and exiting right away if it wasn't set, so
    none of the other statements were executed.


    On 6/7/06, Brent L. Bates wrote:

    Is the `FOO' variable protected with an `if' block? I believe
    that when
    one uses `su' with a command, one will not get a full login, but
    only a
    partial. One can protect things in the .cshrc from being executed
    in
    non-login environments. Near the bottom of my ~/.cshrc file I have
    2 `if'
    checks. One is this:

    if (! $?prompt) exit

    and the other is:

    if ($?ENVONLY == 1) exit

    If one is not in a login environment, the `prompt' variable
    isn't set, at
    least I don't think so. If one is not in a login environment, then
    the last
    one above will definitely cause an exit.
    Some things one doesn't want executed when one isn't actually
    logging in
    and if they are executed, they can cause problems. I've seen this
    happen with
    the `rsh' & `rcp' commands. If some of the ~/.cshrc commands
    aren't prevented
    from being executed in these environments, they can cause weird
    failures.
    Perhaps you have something in your .cshrc file that shouldn't
    be executed
    in a non-login environment and that is why you are not getting your
    environmental variable set.
    I hope this is of some help. Good luck.

    --

    davea wrote:
    > kevin.quigley@gmail.com wrote:
    >
    > > # su - user -c 'echo $HOME'
    > > /home/user
    > >
    > > however, the user's setup file "/home/user/.cshrc" is still not being
    > > read, so $FOO isn't getting set.

    >
    > # su - davea -c 'echo $HOME ; echo $SHELL ; printenv'
    > worked for me on IRIX 6.5.29. As root (where I did the su)
    > showed root stuff, as me showed my .cshrc data.
    >
    > Add $SHELL and printenv to your command and retry.
    > davea



+ Reply to Thread