Distinguish session type in .profile - Unix

This is a discussion on Distinguish session type in .profile - Unix ; Hi, is there a environment variable that indicates if a session has been started via an ordinary login or via "su"? In ~/.profile I need to distinguish if the user has logged in or if it was me via "su ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Distinguish session type in .profile

  1. Distinguish session type in .profile

    Hi,

    is there a environment variable that indicates if a session has
    been started via an ordinary login or via "su"?

    In ~/.profile I need to distinguish if the user has logged in or
    if it was me via "su -v user" in order to run or not run a
    particular program.

    Regards,
    Tim

  2. Re: Distinguish session type in .profile

    Tim Frink wrote:
    > Hi,
    >
    > is there a environment variable that indicates if a session has
    > been started via an ordinary login or via "su"?
    >
    > In ~/.profile I need to distinguish if the user has logged in or
    > if it was me via "su -v user" in order to run or not run a
    > particular program.

    What ia 'su -v'?
    ..profile is only executed be a login shell, so with su an 'su - user' would
    be needed (or -l or --login).

    Bye, Jojo



  3. Re: Distinguish session type in .profile

    > In ~/.profile I need to distinguish if the user has logged in or
    >> if it was me via "su -v user" in order to run or not run a
    >> particular program.

    > What ia 'su -v'?


    Sorry, I meant "su -". :-)

    > .profile is only executed be a login shell, so with su an 'su - user' would
    > be needed (or -l or --login).


    Does this mean that with "su - user" the user's .profile is not executed?
    What do you mean with "su - user would be needed"?

    Regards,
    Tim

  4. Re: Distinguish session type in .profile

    Tim Frink wrote:
    >> In ~/.profile I need to distinguish if the user has logged in or
    >>> if it was me via "su -v user" in order to run or not run a
    >>> particular program.

    >> What is 'su -v'?

    >
    > Sorry, I meant "su -". :-)
    >
    >> .profile is only executed be a login shell, so with su an 'su -
    >> user' would be needed (or -l or --login).

    >
    > Does this mean that with "su - user" the user's .profile is not
    > executed?

    No. It would only be executed with 'su -'

    > What do you mean with "su - user would be needed"?

    In order to get .profile executed.

    Would $0 help you to distinguish between login session and 'su -' session?
    On my system in the 'su -' case, $0 contains "-su" rather than "-ksh" (or
    whatever your login shell is)

    case $0 in
    *-su) echo \"su -\" session
    ;;
    *) echo normal login session
    ;;
    esac

    In case of an su session without -, $0 contains my login shell, but with out
    the '-' prefix ("ksh")
    In the case of ksh you might attempt to handle the difference in the files
    pointed to be $ENV which, if exists, would be executed by every shell, not
    just the login shell.

    Bye, Jojo



+ Reply to Thread