login shell with su? - Help

This is a discussion on login shell with su? - Help ; How do can root start a login shell with su and execute a bash script as the su'ed user?...

+ Reply to Thread
Results 1 to 4 of 4

Thread: login shell with su?

  1. login shell with su?

    How do can root start a login shell with su and execute a bash script as the su'ed user?

  2. Re: login shell with su?

    On 2006-09-07, Angel Tsankov wrote:
    > How do can root start a login shell with su and execute a bash script as the su'ed user?


    man su:

    NAME
    su - run a shell with substitute user and group IDs

    SYNOPSIS
    su [OPTION]... [-] [USER [ARG]...]

    DESCRIPTION
    Change the effective user id and group id to that of USER.

    -, -l, --login
    make the shell a login shell

    -c, --commmand=COMMAND
    pass a single COMMAND to the shell with -c


    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

  3. Re: login shell with su?

    >> How do can root start a login shell with su and execute a bash script as the su'ed user?
    >
    > man su:
    >
    > NAME
    > su - run a shell with substitute user and group IDs
    >
    > SYNOPSIS
    > su [OPTION]... [-] [USER [ARG]...]
    >
    > DESCRIPTION
    > Change the effective user id and group id to that of USER.
    >
    > -, -l, --login
    > make the shell a login shell
    >
    > -c, --commmand=COMMAND
    > pass a single COMMAND to the shell with -c


    I tried
    su - user_name -c script_to_execute

    but the bash shell started by su does not read /etc/bash_profile or ~/.bash_profile, though it should be a login shell.

  4. Re: login shell with su?

    Here's a scenario in which su from coreutils 5.2.1 does not
    invoke bash as a login shell:

    root>su --version
    su (coreutils) 5.2.1
    [...]
    root>echo "echo \"This is .bash_profile.\"" >~usr1/.bash_profile
    root>cat ~usr1/.bash_profile
    echo "This is .bash_profile."
    root>echo 'echo $PATH' | su - usr1
    /usr/bin:/bin
    # NOTE: bash was not invoked as a login shell, which is
    unexpected
    root> su - usr1
    This is .bash_profile.
    usr1>
    # NOTE: as expected, bash was invoked as a login shell

    Is this really a problem in su and if so, is there a patch for
    it?


+ Reply to Thread