Operating System - HP-UX
1753936 Members
10129 Online
108811 Solutions
New Discussion юеВ

HPUX11.11 - Using the script command and logname - error is "could not get login name"

 
SOLVED
Go to solution
Mark Parsons
Valued Contributor

HPUX11.11 - Using the script command and logname - error is "could not get login name"

Hi,

I am trying to use logname having started a script command and it comes back with:

# script me
Script started, file is me
# logname
logname: could not get login name

However come out of the script command and all is fine:

# script me
Script started, file is me
# logname
logname: could not get login name
#
Script done, file is me
# logname
mparsons

Is there a workaround for this?

Kind Regards,

Mark P.
7 REPLIES 7
Michael Steele_2
Honored Contributor

Re: HPUX11.11 - Using the script command and logname - error is "could not get login name"

HI

Try both:

a)
LOGNAME=`logname`
print $LOGNAME

b)
LOGNAME=$(logname)
print $LOGNAME
Support Fatherhood - Stop Family Law
James R. Ferguson
Acclaimed Contributor

Re: HPUX11.11 - Using the script command and logname - error is "could not get login name"

Hi Mark:

The 'script' command starts a new shell process. When this process uses 'logname' to attempt to obtain the login terminal name, 'getlogin()' is called to find the name of the user logged in on a terminal associated with the calling process. This is done by searching the accounting database 'utmpx'. Since at that point, the process id of the 'script' command can't be matched, 'logname' fails.

You need to take the 'LOGNAME' variable from your environement, instead:

# echo ${LOGNAME}

Regards!

...JRF...

Regards!

...JRF...
Mark Parsons
Valued Contributor

Re: HPUX11.11 - Using the script command and logname - error is "could not get login name"

Thanks for that - it does work - but doesn't help in the situation that I am working on.

The oracle account can only be accessed by relevant users and not as a direct login so I've got the following set in /etc/profile:

name=`logname`
if [ $name = oracle ]
then
echo $LOGNAME not allowed to login...only su
exit 0
fi
end

I'm also doing an audit trail on the relevant users by using the script command so this is part of the users profile:

Date=`date +'%Y%m%d%H%M%S'`
script /logs/script/$LOGNAME.$Date 2>/dev/null

So oracle cannot login direct. The user logs in direct - the session is copied into the script - then they do the "su - oracle" and then from the /etc/profile gets the message:

logname: could not get login name

Obviously the su login process and the script continues successfully - I just want to get rid of the "logname: could not get login name" message - anything will do!

Kind Regards,

Mark P.
Michael Steele_2
Honored Contributor

Re: HPUX11.11 - Using the script command and logname - error is "could not get login name"

su - oracle
is not the same as
su oracle

'-' means accept a new oracle environment
without means maintain the current environment.
Support Fatherhood - Stop Family Law
Steven Schweda
Honored Contributor
Solution

Re: HPUX11.11 - Using the script command and logname - error is "could not get login name"

> [...] I just want to get rid of the
> "logname: could not get login name"
> message - anything will do!

> name=`logname`

name=` logname 2> /dev/null `

dyi # script
Script started, file is typescript
dyi # name=` logname `
logname: could not get login name
dyi # name=` logname 2> /dev/null `
dyi #
Mark Parsons
Valued Contributor

Re: HPUX11.11 - Using the script command and logname - error is "could not get login name"

Fantastic - thanks all - this has now worked.
Mark Parsons
Valued Contributor

Re: HPUX11.11 - Using the script command and logname - error is "could not get login name"

Now working......