The logname command

Forum rules
Before you post please read this

The logname command

Postby swiftlinuxcreator on Mon Oct 31, 2011 1:00 pm

In a script, how do you access your regular username when you're executing as root?

In antiX Linux as root, entering "logname" gives me my regular username.

in LMDE as root, entering "logname" gives me "logname: no login name". How do I correct this?
swiftlinuxcreator
Level 2
Level 2
 
Posts: 60
Joined: Sun Jan 30, 2011 9:31 pm

Linux Mint is funded by ads and donations.
 

Re: The logname command

Postby Pilosopong Tasyo on Mon Oct 31, 2011 11:27 pm

swiftlinuxcreator wrote:...access your regular username when you're executing as root?

Did you mean perform a command as another user? If this is the case you can use sudo -u.
Image
o Give a man a fish and he will eat for a day. Teach him how to fish and he will eat for a lifetime!
o If an issue has been fixed, please edit your first post and add the word [SOLVED].
User avatar
Pilosopong Tasyo
Level 6
Level 6
 
Posts: 1176
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: The logname command

Postby Anakinholland on Tue Nov 01, 2011 11:10 am

Pilosopong Tasyo wrote:Did you mean perform a command as another user? If this is the case you can use sudo -u.


He/she meant that while being su-ed to root you can execute the command "logname" to display the username of the user you're su-ing with :)

@swift, it might be a distro-issue? It works fine on my RHEL6-laptop, not my Mint-netbook.

This topic might explain it fairly well I think? http://forums.gentoo.org/viewtopic-t-28 ... art-0.html

Basically Debian/Ubuntu/Mint logs sessions (usernames) in a different location than where logname is looking. The solution posted there is no longer valid though, my Linux Mint 11 doesn't even have an inittab anymore... :S

However, in directory /etc/init, I do see tty[1-6].conf, which hold relating data.

Cheers!
Please Edit your initial post title and add [SOLVED] once your question is resolved.
User avatar
Anakinholland
Level 3
Level 3
 
Posts: 145
Joined: Sun Oct 30, 2011 8:09 am


Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests