Re: logname (222 Views)
Reply
Occasional Visitor
Akash_8
Posts: 4
Registered: ‎07-19-2004
Message 1 of 7 (222 Views)
Accepted Solution

logname

We have a new server with HP UX 10.2. We have a few scripts on our old server which uses the "logname" function to create file names.
These scripts worked for years on our old server.
However on our new server logname fails - it comes up with an error - logname: could not get login name. But sometimes if the user logs out and logs back in again, logname works ! Our users also use tsm(if this is the reason?) .
1)Does anyone know the reason for this behaviour.
2)If I substitute logname with a function which returns id -un, would this be a more stable option ?
ANy solution much appreciated as this is quite urgent. Many Thanks
Honored Contributor
Bill McNAMARA_1
Posts: 3,866
Registered: ‎11-14-2000
Message 2 of 7 (222 Views)

Re: logname

try restripting with uid -i or something like that, however, are your _REALLY_ sure this is a new server? It's running 10.20!
It works for me (tm)
Occasional Visitor
Akash_8
Posts: 4
Registered: ‎07-19-2004
Message 3 of 7 (222 Views)

Re: logname

Bill , do you suggest uid instead of id -un ?
The reason I asked is there is a function already on our server which uses id -un.
Yes Bill- you're right about our server- It is only sort of "new" - only the hardware !!
Honored Contributor
Mark Grant
Posts: 2,712
Registered: ‎04-01-2003
Message 4 of 7 (222 Views)

Re: logname

Personally I would always go with "id -u" but you could always try $LOGNAME
Never preceed any demonstration with anything more predictive than "watch this"
Honored Contributor
Jose Mosquera
Posts: 1,013
Registered: ‎06-27-2002
Message 5 of 7 (222 Views)

Re: logname

Hi,

Maybe a path definition will be the key, pls assigns the "logname" command with the full path, to determine this use the following command:
#whence logname

If the full path is used into the script files, pls compare it with the "whence" command output, in older systems the path may vary.

Try and tell me something.

Rgds.
Occasional Visitor
Akash_8
Posts: 4
Registered: ‎07-19-2004
Message 6 of 7 (222 Views)

Re: logname

Jose Maria,
Both the systems are using the same path , users have the same path on both systems logname is in /usr/bin/logname. But I am intigued as to why it works sometimes when users log out and log back in ? If it was the path, it should always fail, should it not ?
Honored Contributor
Dietmar Konermann
Posts: 1,207
Registered: ‎02-04-1998
Message 7 of 7 (222 Views)

Re: logname

The logname(1) command uses the getlogin(3C) library call to find the login name.

From the getlogin(3C) man page:

---
The getlogin() function retrieves the name of the user currently logged in on a terminal associated with the calling process, as found in /etc/utmp.

At least one of the standard input, standard output, or standard error must be a terminal. For the first of these found that is a terminal, a user must have logged in on that terminal, and that terminal must be the controlling terminal of the session leader process of the calling process's session.
---

So I would assume that *sometimes* the session you are calling logname(1) from is not properly recorded in /etc/utmp. Indeed prgrams that create new sessions like getty(1M), rlogind(1M), telnetd(1M) and ... yes ... also tsm(1) are responsible for recording records to /etc/utmp, using library calls like pututline(3C).

All you can do for 10.20 is "patching, patching and also patching" the above commands/daemons along with libc.

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.