LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 02-05-2014, 03:51 AM   #1
adb101
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Rep: Reputation: Disabled
Question Detecting if shell is an "su" shell in RHEL 6


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.

Many thanks

AB
 
Old 02-05-2014, 03:59 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,705

Rep: Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824
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.
 
1 members found this post helpful.
Old 02-05-2014, 04:06 AM   #3
adb101
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Hi

Thanks - that works a treat!

I'd been banging my head against that for a while..!

AB
 
Old 02-05-2014, 04:35 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,705

Rep: Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824Reputation: 7824
glad to help you.
If you really want to say thanks just press YES.
 
  


Reply

Tags
login, rhel 6, shell, su


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to replace "ö" to "p" in shell scripting with "sed" meninmech Programming 5 06-22-2012 03:58 PM
How to set the font-size for "xterm" terminal-emulator (running "bash" shell) ajaygarg Linux - Desktop 1 03-09-2012 01:38 PM
Shell script: I have string "abc____def____ghi", how to make "abc def ghi" vouser Programming 8 03-09-2010 11:01 PM
How to prevent "leak" into Shell from a customized shell menu script dctw Programming 11 12-28-2009 05:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration