The logname command

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
swiftlinuxcreator

The logname command

Post 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?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
Pilosopong Tasyo
Level 6
Level 6
Posts: 1432
Joined: Mon Jun 22, 2009 3:26 am
Location: Philippines

Re: The logname command

Post 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.
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].
Anakinholland

Re: The logname command

Post 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!
Locked

Return to “Scripts & Bash”