Find logon user based on executed script proc id


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find logon user based on executed script proc id
# 1  
Old 01-21-2014
Find logon user based on executed script proc id

Hi,
i have requirement to find logged in user based on process id. i have below scenario.

1. all my users will logon to unix box using ssh from windows system.
2. after successful logon they will sudo to common user. ex. sudo -su edadm

lot of users are executing jobs from edadm user and want to find out who executed particular job.

using ps -eaf command i am able to find out process id and user name but that is displaying edadm user. But i want to know actual user name who logged on to system and executed that particular script.

Ex. User1 is logged into unixbox and executed sudo su - edadm and executed script1.
edadm 18892 12778 0 04:28 pts/20 00:00:00 script1
I am able to see edadm user is executing script1 but my expectation is to find out USER1 because he is the one who is executing script.
# 2  
Old 01-21-2014
You may want to try sth like
Code:
{ echo $$; ps -elf ; } | 
awk     'NR==1          {PID=$1; next}
                        {USER[$4]=$3; PPID[$4]=$5}
         END            {ME=USER[PID]
                         while (USER[PID]==ME) PID=PPID[PID]
                         print USER[PID]
                        }
        '

# 3  
Old 01-21-2014
If the terminal is pts/20, then:-
Code:
ps -ft pts/20

Of course, this only works whilst the process is running. Perhaps you need to code some tracing/logging into your scripts to write messages to the syslog. When switched to another account, the syslog message is still written by the user who originally logged on. Use the logger command.

It may be as simple as putting:-
Code:
logger "in $pwd running \"$0\" with parameters \"$*\""

.... into your scripts. The \" will allow you to get a quote into the logged message.



I hope that this helps,
Robin
Liverpool/Blackburn
UK
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find Original user who executed the command

Hi Team, Please help me with the below question. SunOS 5.10 Shell: -bash I am trying to find the original user who executed a command on my development server. In my dev server users login using their personal id and sudo to a common id using 'sudo -u commonid -i'. Once logged in as... (6 Replies)
Discussion started by: sam99
6 Replies

2. UNIX for Dummies Questions & Answers

Parse User Logon Count

Hey, My access.log for one application is not rolled over. I would like to get users count. Right now I am doing cat logon.list | grep 2013-09-11| |grep Succeeded | wc -l Since the file doesnt rotate out I have to grep for new date/ I tried to specify DATE=date "+DATE:... (2 Replies)
Discussion started by: brabored
2 Replies

3. Shell Programming and Scripting

Script interacts with user , based on user input it operates

i have a script which takes input from user, if user gives either Y/y then it should continue, else it should quit by displaying user cancelled. #!/bin/sh echo " Enter your choice to continue y/Y OR n/N to quit " read A if then echo " user requested to continue " ##some commands... (7 Replies)
Discussion started by: only4satish
7 Replies

4. Shell Programming and Scripting

Limit a user's login prompt upon logon

Hey Am new to scripting in aix 5.3 I need to write a script to limit a user's logon prompt to an interactive menu based upon logon and nothing else. Any ideas much appreciated. :wall: (4 Replies)
Discussion started by: mills
4 Replies

5. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

6. Solaris

Help a user logon in SUN SOLARIS 10 ?

I logon with root user, then ok, but as a user logon is not, it is the login window forever ah, wishes to receive help from members of the forum, thanks very much. (2 Replies)
Discussion started by: tampc
2 Replies

7. Solaris

Solaris 8 logon problem with normal user

Hello. I have problem in Solaris 8. I can logon cde with root there is no problem. When I logon with normal user I am recieving black screen after 10 15 second login screen (cde pasword screen) coming again. 1 years ago we resolved same problem. We found a file It must be run with admin... (1 Reply)
Discussion started by: FATIH1453
1 Replies

8. Solaris

user logon details

how can i identifying whose are logged in last few days,time and date also want. what i will do for get that information (2 Replies)
Discussion started by: sijocg
2 Replies

9. Cybersecurity

Help Required: Command to find IP address and command executed of a user

Hi, I am trying to write a script which would figure out who has run which command and their IP. As i dont have any clue as to which commands would do this job, i request some gurus to help me on this. Thanks Vishwas (2 Replies)
Discussion started by: loggedout
2 Replies

10. UNIX for Dummies Questions & Answers

Multiple user logon

I keep trying to use ssh shell to access my school's unix server from home and I get this error message: "This user id is logged on too many times. Please end some logins to reduce your total number of logins to no more than 1. Please do so in the next 1 minutes or you will be logged out... (3 Replies)
Discussion started by: hawkshot
3 Replies
Login or Register to Ask a Question