How to get a login name of a person who used 'su' and act with different user-name?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to get a login name of a person who used 'su' and act with different user-name?
# 1  
Old 02-05-2009
How to get a login name of a person who used 'su' and act with different user-name?

I need to realize the user login name after he/she used the 'su' command to log under another name (for specific privileges.)

I am on SunOS v5.6, and here by now I could not find a way to figured it out.
In another Thread I've get an advise from Linux user to use 'ps afxj' that display a processes tree and shows up the originated 'su' command.
But on Sun I could not find a way to get something simular that would display the 'su'

The main reason for that task is to use the 'write' comand to send a message to people's terminal who is loged by 'su' as a specific user.
I have a script that runs background and monitoring some condition. I would like it time to time to send some message.
It is started by someone, who used 'su', but could after that close the seccion and even log off completely.
Although all the time someone has use the specific user-name, loged by 'su' - it is a production control name.
I need the script to be able send a mesage directly to anyone who now is under that production-control-logname.

How that could be done in Sun UNIX?
# 2  
Old 02-06-2009
Even if you don't have a pretty version of ps (with -forest flag), nor
the ptree app, you can still get the parent pid from a process when
you run a ps -ef.

You should be able to find your process (owned by root), and its
pid. Next to it is the parent pid. Now look for this pid, and _its_
parent pid. And so on.

Another way of finding out more about a process is by looking at its
environment variables. This will work if the user did a su, without
the '-' char as an argument, since most of the original environment
variables will be retained.

pargs -e <pid>
# 3  
Old 02-09-2009
fimbo - or I could not understand what you advice, or I did not explain well what I need to have.
You are right, ps -ef could drive me to original process - completely understand PID and PPID relation.

But in our sistem the 'su' command is not visable.
So, how I can know who is under the 'support' login?

One person start a background script and closed the session.

After some period of time script need to display a message, but original session is not available.
But it must to be someone else under the same 'support' id, logged with 'su'

Using the 'write' command is not possible - the 'write' do not see the person after the 'su' - it sais: the 'support' person is not logged.
But I see many processes of the 'support' person and can't write a message to that user.

The 'ptree' is available on this system, but there is no 'su', also
See example.
I have logged in the system with my log ID, and 'su' for the same id (I do not have any other id available).
I have start 'tail -f ..' to recognize process
See the part of 'ptree':
Code:
            17175 more -s /tmp/mpwMaqGH
  18599 in.telnetd
    18602 -ksh
      18662 bash
        18727 ksh
          18766 bash
            18859 tail -f tst.sh
746   /usr/lib/nfs/statd

...
I think the ptree is usefull to see, but to follow to the originating PID from script is not comportable.
# 4  
Old 02-10-2009
So, I have resolve my own task, although the main question of this thread is not resolved.

In my situation I knew the log name that is used to start process. And, how it was advised, using the 'ps' though real terminals, I get the acctual log name of the person, who been loged in before 'su'.
I have put it into a function:
Code:
main_log_nm ()
{
    typeset usr       tr        ;  # input user name; related to usr terminals;
    typeset usrs_all usrs_les;  # all users on those terminals; all users, lewss on usr
      # if no user name in input, use name of requester
    [[ -z $1 ]] && usr=$(whoami) || usr=$1;
      # get line of related terminals (backgroung jobs has '?' for TT (terminal);  
    tr=$(ec $(ps -o tty -u $usr|grep -v '^?'|grep -v TT|sort|uniq )|sed 's/ /,/g');
      # now get all users associated with found terminals - originaly a person will have a terminal
    [[ ! -z $tr ]] && {
      usrs_all=$(ps -o user -t $tr | grep -v  USER |sort|uniq);
        # remove from all users the requested user name (as it 'su'id)
      usrs_les=$(ec $usrs_all|sed "s/ *//g; s/$usr//g");
        # if there is any other name than the requested, do not return the requested name
      [[ -z $usrs_les ]] && /usr/bin/echo $usrs_all || /usr/bin/echo $usrs_les
    }  #END of 'if any terminal is found (so, someone is loged in)'
}
#  END of  main_log_nm

(If you see anythink incorrect or should/could be done different - I will appreciate your hints!)
After that it is easy to use 'write' for each returned name

BUT, if the task is to realise who is logged under 'su' - I DO NOT HAVE a solution!

If you see how it could be done in such system as our (where 'su' command is not showed in 'ps' list and represented as a regular log,) show it here.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Prevent user from creating new user from his login

Hi Experts, Need your support Redhat 6.5 I want to create a user with all(read, write, execute) privileges except that user should not be able to create any new user from his login to perform any task. (10 Replies)
Discussion started by: as7951
10 Replies

2. Shell Programming and Scripting

Login into another user from user inside script

now i have logged in username : ramesh in unix Now i have to created script file to login into another user and have run a command inside that user and after executing the command i have to exit from that user. Inside script, i have to login into su - ram along with password : haihow and have to... (4 Replies)
Discussion started by: rammm
4 Replies

3. AIX

User Account Login Login on your AIX server

I want to learn AIX. I would like to find someone who would be willing to give me a login to their AIX home lab server. My intent is to poke around and discover the similarities and differences of AIX compared to other *NIXs. I am a UNIX admin so I can think of what some immediate concerns may... (1 Reply)
Discussion started by: perl_in_my_shel
1 Replies

4. Shell Programming and Scripting

How to Login as another user through Shell script from current user[Not Root]

Hi Every body, I would need a shell script program to login as different user and perform some copy commands in the script. example: Supppose ora_toms is the active user ora_toms should be able to run a script where user: ftptomsp pass: XXX should login through and run the commands ... (9 Replies)
Discussion started by: ujjwal27
9 Replies

5. AIX

User login time

I want to set the "logintimes" variable for a user on a server who need access mornings and night how to I set the "logintimes" I want the user to log in from 08:00 to 12:00 and 17:00 to 21:00 is this possible? (1 Reply)
Discussion started by: daveisme
1 Replies

6. Solaris

error message rmclomv ... SC Login Failure for user Please login:

Hello World ~ HW : SUN Fire V240 OS : Solaris 8 Error message prompts 'rmclomv ... SC login failure ...' on terminal. and Error Message prompts continually 'SC Login Failure for user Please login:' on Single Mode(init S) The System is in normal operation, though In case of rain, Can... (1 Reply)
Discussion started by: lifegeek
1 Replies

7. Shell Programming and Scripting

Running script from other user rather than login user

Hi, My requirement is that i am login from ROOT in a script but when any command is coming which is logging to sqlplus then i have to run it with normal user as only normal user have permission to connect to sqlplus . i tried making a script like this : #! /bin/ksh su -... (3 Replies)
Discussion started by: rawatds
3 Replies

8. UNIX for Dummies Questions & Answers

I create user but i cant login the user i created.

I created a user, i login as a root. I add him in the group where he can access and login as a root! I checked it in users' list and in group's list, he is there. My problem is this, I cant login using the username/account I just created! What should i do to use and login the user/account i've just... (5 Replies)
Discussion started by: jerome
5 Replies

9. Shell Programming and Scripting

User Login Limit

Gud day :) We have a limited user login so we want to restrict 1 login per user. We have added below script in each user's profile but it is not working :confused: , I displayed the output for COUNT (by inserting echo command) but the value is always 1. Hope you could help me. Thanks ;) ... (3 Replies)
Discussion started by: lancemendioro
3 Replies

10. UNIX for Advanced & Expert Users

Login User

Dear all members I've a question basd on an AIX enviroment. In here I've two administrative users, are used for the running application (SAP). Now my problem's, that's not possible to login over the "normal" Loginscreen as such a user. If I try this, the FTP connection will closed at once. It's... (6 Replies)
Discussion started by: olli2002
6 Replies
Login or Register to Ask a Question