Page 1 of 1

The logname command

Posted: Mon Oct 31, 2011 1:00 pm
by swiftlinuxcreator
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?

Re: The logname command

Posted: Mon Oct 31, 2011 11:27 pm
by Pilosopong Tasyo
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.

Re: The logname command

Posted: Tue Nov 01, 2011 11:10 am
by Anakinholland
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!