LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-06-2008, 05:35 PM   #1
kornelix
Member
 
Registered: Oct 2005
Location: Germany
Distribution: Ubuntu
Posts: 56

Rep: Reputation: 24
how to get $HOME for the login user ID when "su" has been used


I need to get the home directory of the login user ID as opposed to the effective user ID (which changes when "su" is used). I can get the login user ID ($USERNAME) but I cannot find a way to get the home directory of a known user that is not the current user. I need a shell command like the c-lib getpwent() function. It must be there somewhere but I cannot find it.
 
Old 04-06-2008, 06:43 PM   #2
blacky_5251
Member
 
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 4&5, Fedora 10, CentOS 5.4, IPCop
Posts: 569

Rep: Reputation: 55
Try this:-
Code:
grep $LoggedInUser /etc/passwd | cut -f 6 -d ":"
Where $LoggedInUser holds the value of the user that logged in - not the su'ed user id.
 
Old 04-07-2008, 03:39 AM   #3
kornelix
Member
 
Registered: Oct 2005
Location: Germany
Distribution: Ubuntu
Posts: 56

Original Poster
Rep: Reputation: 24
Thank you blacky!!
 
Old 04-07-2008, 03:45 AM   #4
kornelix
Member
 
Registered: Oct 2005
Location: Germany
Distribution: Ubuntu
Posts: 56

Original Poster
Rep: Reputation: 24
$LoggedInUser is not defined on my system (Ubuntu) but $USERNAME works.
 
Old 04-07-2008, 04:01 AM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Try using "su -" which will execute the shells login rc files and provide a login-like shell environment.

Having said that, on my debian box, su always sets HOME, no matter if I use the "-" method or not.
 
  


Reply

Tags
home


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
NFS problem: "Could not chdir to home directory /home/USER: Permission denied" sumanc Linux - Server 4 07-22-2010 04:12 PM
cant login. "no directory /home/chris!" qwijibow Linux - Newbie 5 02-26-2009 12:58 PM
NIS client login "cannot find user name for user ID" danielbourne Linux - Networking 2 08-24-2006 04:16 AM
permissions of my /home/"user" directory error darkleaf Linux - Software 10 09-26-2004 02:08 AM
RH9 NIS login error: "home directory does not exist" airrr Linux - Networking 2 08-06-2003 01:47 PM


All times are GMT -5. The time now is 01:21 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration