Operating System - HP-UX
1834800 Members
2835 Online
110070 Solutions
New Discussion

logname: could not get login name

 
Mauro Gatti
Valued Contributor

logname: could not get login name

Doing this command i get:

$ logname
logname: could not get login name

but if I do:
$ echo $LOGNAME
mgatt

I get my logname...

How can I fix the problem?

Thank You
Ubi maior, minor cessat!
7 REPLIES 7
Steve Steel
Honored Contributor

Re: logname: could not get login name

Hi

Do

tty

result is something like

/dev/ttyp1

name is ttyp1

Then

ll -i /dev/ttyp1 /dev/*/ttyp1

211202 crw--w---- 2 steves tty 17 0x000001 May 20 10:38 /dev/pty/ttyp1
211202 crw--w---- 2 steves tty 17 0x000001 May 20 10:38 /dev/ttyp1

If the inode numbers do not match then you need to remake your special files

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Bill Hassell
Honored Contributor

Re: logname: could not get login name

$LOGNAME is just an environment variable set when you first login. But logname is a system call to getlogin() which in turn reads the entries in /etc/utmp. /etc/utmp is a somewhat unstable file in that user programs are supposed to properly handle updates in this file. But crashed connections and other problems can leave orphaned entries in the utmp file thus creating the symptom you are seeing. You might is the command fwtmp to cleanup utmp and remove inconsistent entries, or just reboot and the file will be rebuilt.


Bill Hassell, sysadmin
john korterman
Honored Contributor

Re: logname: could not get login name

Hi Mauro,
if you execute
# who -u
is mgatt then currently logged on?

regards,
John K.
it would be nice if you always got a second chance
Bill Douglass
Esteemed Contributor

Re: logname: could not get login name

I've run into this when using logname and OpenSSH.

After adding the latest Quality Pak bundle for 11.0 (March 2003), I noticed that logname started failing for users connected via ssh.

Tracing the logname command, it appears that the updated binary adds calls to getsid(PID), which fail with EPERM or ESRCH errors. This causes logname to fail with the above error message.

whoami will return your effective username.

who am i | awk '{print $1}'
will return your real username (as determined from utmp).
Ross Zubritski
Trusted Contributor

Re: logname: could not get login name

I have run into this after patching. Try an insf -e and see if that clears up your issue.

Regards,

RZ
Richard Steenburg
New Member

Re: logname: could not get login name

I had the same problem, but I couldn't not use logname b/c shareplex uses it all over the place. The problem has to do with process groups and setting UsePrivilegeSeparation to 'no' in the sshd_config file fixed made logname work again.
Brian Crabtree
Honored Contributor

Re: logname: could not get login name

You might want to verify that your user has the ability to read the /etc/passwd file. Try executing "id" and see if it returns your username.

Thanks,

Brian