Knowing the user who is executing my script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Knowing the user who is executing my script
# 1  
Old 01-19-2011
Knowing the user who is executing my script

Hi, is there any way? I thot of id but it doesnt work quite well Smilie
# 2  
Old 01-19-2011
Right now?
Code:
 
#!/usr/bin/ksh
 
zp=$( fuser script_file.sh 2>/dev/null )
 
if [ "$zp" != "" ]
then
  ps -fp "$zp"
fi

Ongoing? Just add some logging to your script:
Code:
date "+%Y-%m-%d %H:%M:%S $LOGNAME $$ $0 $# args( $* )" >> ~me/my_log.txt

# 3  
Old 01-19-2011
Some commands you might find usefull:

Code:
$ whoami
$ id -un
$ echo $LOGNAME
$ echo $SUDO_USER

Note SUDO_USER is only usefull if you have/use sudo in your environment and returns the user who called sudo instead of the current userid
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Restrict a user from Executing particular command

hi how to restrict a user ro run rm command. In this scenario we have a user/group has below in sudoers user ALL=(ALL) ALLis there a way to restrict the user from just executing rm command (9 Replies)
Discussion started by: robo
9 Replies

2. UNIX for Dummies Questions & Answers

How to switch the user before executing a shell script from web page??

hi, i want to execute a shell script as a different user. the flow is like this. there is a html web page from which i have to call a shell script. web server is apache. to call the shell script from html page, a perl script is required. so the html page calls the perl script and the perl... (2 Replies)
Discussion started by: Little
2 Replies

3. Shell Programming and Scripting

Shellscript not executing further after sudo over a user

Hi, I am writing a switch case statement and one of the option contains sudo to a particular user and then perform some steps after that but my script is unable to proceed with further execution after doing sudo over the user. Could you please suggest an workaround for this. (1 Reply)
Discussion started by: adityam
1 Replies

4. Shell Programming and Scripting

getting a string from user while executing a tcl script

Hi All, I am executing a Tcl script and i am trying to get the user input while they execute the script at start itself like >>filename.tcl USERINPUT and then i will take this userinput inside the the tcl assign it to some variable for further manipulation/processing ...... can anyone pls... (1 Reply)
Discussion started by: sukrish
1 Replies

5. Shell Programming and Scripting

Executing program with Perl script but needs user input

Hello, I'm running a perl script to execute a program through my Unix command line. The program requires a user input but I want to automatically have perl input the string. Is there a way to do this? Thanks (1 Reply)
Discussion started by: leonard2352
1 Replies

6. SCO

Executing script with root privilages from a user login

I need to regular users to be able to launch a script which does something requiring root privilages. I've tried using chmod 4755 which gives it -rwsr-xr-x permissions but it still can not be run as the regular user. (1 Reply)
Discussion started by: checkpro
1 Replies

7. UNIX for Dummies Questions & Answers

Find the user executing a script

How do i in a script determine the user that is executing it? (2 Replies)
Discussion started by: Chiefos
2 Replies

8. Shell Programming and Scripting

Executing Script of a different user on Same Machine

Hi, I want to execute a script - of different user from my script. I have tried the su command su - username -c "scriptname" it works but asked for password. Is there any way for supplying the password to it thru script, not interactively. Or is there any other way to achieve the... (5 Replies)
Discussion started by: yeheyaansari
5 Replies

9. AIX

Knowing when is the user id expiring

HI, Do we have a command in AIX which will let us know when is the user id password getting expired!! Any advice will be of great help!! Thanks, Siddharth (0 Replies)
Discussion started by: siddhhuu
0 Replies

10. UNIX for Dummies Questions & Answers

user executing priveleged commands

hey peeps i am pretty much new to unix, my first semester at uni, so if anyone can help, would be greatly appreciated. how the hell is it possible for a user to execute priveleged commands without the user having a superuser password?? if anyone can help me, i would appreciate it very... (2 Replies)
Discussion started by: 30177005
2 Replies
Login or Register to Ask a Question