Get current logged in user from a script run as root.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get current logged in user from a script run as root.
# 1  
Old 08-17-2010
Error Get current logged in user from a script run as root.

Ok, so, in order to install some dependencies of a program I made, a script has to be run as root. The thing is that I have to copy some things into the home folder of currently logged in user, but the variable $HOME returns '/root' and the $USER returns 'root' Smilie
Is there any way to see who is currently logged in?SmilieSmilieSmilie
# 2  
Old 08-17-2010
1) What Operating System and Shell are you using?
2) Did you log in as the user before becoming root?
3) How did you gain root permissions? (su , sudo ?)
4) What reply do you get for:
Code:
who am i

5) I'm assumig that this is not a single-user workstation.
# 3  
Old 08-17-2010
1)Ubuntu 10.04 bash
2)yes
3)sudo su
4)In the command 'who am i' I get as a response
Code:
alex     pts/0        2010-08-17 17:34 (:0.0)

but I am running in a single user machine. I dont know the answer if there were more than one users in my system ( 5) )

---------- Post updated at 01:30 PM ---------- Previous update was at 09:38 AM ----------

I told you what I have! Any other reply?SmilieSmilie
# 4  
Old 08-17-2010
Thanks for your reply :-)

So, I have to tell the users to use su -m to become root and then run the script??? It's quite confusing don't you think?

Is there any way to access the currently logged on user when being root?
# 5  
Old 08-17-2010
try logname
# 6  
Old 08-17-2010
Ouaoooo this solves everything!!! Thank you very much!!!
# 7  
Old 08-18-2010
Good answer. "logname" returns the same user as "who am i" but is easier to work with.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run script automatically on reboot as root user?

Hi friends,,, I am running one server on Ubuntu 12.04 LTS 32-bit, some times my pc restarts automatically, with no reason, I have a script to start server which requires root password. in this directory /myserver/start_server.sh How can I do this ? and some scripts I am having that I... (1 Reply)
Discussion started by: Akshay Hegde
1 Replies

2. Shell Programming and Scripting

Script to run commands as root user

Hello I have a script which is working fine so far to generate HTML file. Now i am wondering how do i include a syntax where it can change itself to root user and execute a specific commands as root user. Please help, Thanks in advance. -Siddhesh (2 Replies)
Discussion started by: Siddheshk
2 Replies

3. 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

4. Shell Programming and Scripting

Need to run a bash script that logs on as a non-root user and runs script as root

So I have a script that runs as a non-root user, lets say the username is 'xymon' . This script needs to log on to a remote system as a non-root user also and call up a bash script that runs another bash script as root. in short: user xymon on system A needs to run a file as root user and have... (2 Replies)
Discussion started by: damang111
2 Replies

5. Shell Programming and Scripting

current logged in user

Hey guys I need a script that reads a login name and verifies if that user is currently logged in i have found few commands like "who" and "users" but i wonder how can i verify it that login name is logged in or not? (3 Replies)
Discussion started by: nishrestha
3 Replies

6. Shell Programming and Scripting

Can root user run chmod 000 permission shell script?

Hi, I have a shell script file which is set to access permission 000. When I login as root (sudo su) and try to run this script, I am getting the Permission denied error. I have read somewhere that root admin user can execute any kind of permission script. Then why this behavior? However, I can... (1 Reply)
Discussion started by: royalibrahim
1 Replies

7. UNIX for Dummies Questions & Answers

How to allow access to some commands having root privleges to be run bu non root user

hi i am new to unix and i have abig task. i have to \run particular commands having root privileges from a non root user. i know sudo is one of the way but i need sum other approach kindly help Thanks (5 Replies)
Discussion started by: suryashikha
5 Replies

8. UNIX for Advanced & Expert Users

FTP run by cron only works if user logged in?

I set up a cron job to FTP to another machine. If I have not logged in before the time the cron is set to run, then the ftp program won't connect. I have run this cron on other boxes (diff networks) and it works fine...it is just this one. If anyone has any suggestions as to what would be... (5 Replies)
Discussion started by: vincaStar
5 Replies

9. Shell Programming and Scripting

How a normal user run a script including root privileaged commands

Dear all Ihave written a script in Hpux9.0, the ecript is working fine if I run it from root command prompt But when I am running it thru /etc/profile or /user/.profile and login as a normal user, the owner of the process running the script is the normal user & hence cant run a root privileaged... (7 Replies)
Discussion started by: initin
7 Replies

10. Shell Programming and Scripting

run a script on logout by a non-root user

hi , i need to run a script that delete files when i logout as a user other than root user . I have tried out using .bash_logout but that doesnt seem to work , so any alternative for this to be done. Thanks in advance, Harsha (6 Replies)
Discussion started by: harsha10
6 Replies
Login or Register to Ask a Question