1748145 Members
3527 Online
108758 Solutions
New Discussion юеВ

logname

 
SOLVED
Go to solution
Akash_8
New Member

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
6 REPLIES 6
Bill McNAMARA_1
Honored Contributor
Solution

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)
Akash_8
New Member

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 !!
Mark Grant
Honored Contributor

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"
Jose Mosquera
Honored Contributor

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.
Akash_8
New Member

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 ?
Dietmar Konermann
Honored Contributor

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)