[SOLVED] Detecting if shell is an "su" shell in RHEL 6
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am attempting to work out whether a users current shell is a "direct" login shell (i.e. the user logged in from the login prompt) or whether the shell is a result of an "su -" to another user. The requirement is because I have a shell script that only needs to provide output on a direct login and not after an "su".
I placed the script in /etc/profile.d so it currently gets executed during a direct login and whenever an "su -" is executed. Ideally I'd like to find a way of querying the current session from within the shell script to see if it was as a result of an su and then act accordingly.
there is a trick to do that, probably you can use it:
the command "who am i" will return the owner of the current terminal and not the actual user. Therefore you will get the user who opened that terminal before executing any su or similar command.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.