System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

logname command do not remotely via ssh

SOLVED
Go to solution
skt_skt
Honored Contributor

logname command do not remotely via ssh

# ssh hostname who
/usr/bin/logname: no login name
xxxxx pts/3 Mar 29 07:08

# ssh hostname logname
/usr/bin/logname: no login name
logname: no login name
# echo $?
1

any one seen/experienced a similar situation?Not sure why logname is failing. Both source and target are RHEL AS U4
6 REPLIES
Steven E. Protter
Exalted Contributor

Re: logname command do not remotely via ssh

Shalom Santhosh,

Check to see that the user exists on both systems and has the same mumeric id in /etc/passwd .

The message seems to indicate the login name does not exist on the target system.

Try:
whoami
who am i

enclose multiple command line parameters in double quotes

try ssh username@servername

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Matti_Kurkela
Honored Contributor

Re: logname command do not remotely via ssh

When you run SSH with a remote command, SSH assumes the remote session will be non-interactive and will allocate no pseudo-TTY at the remote end. This may confuse tools like "logname", if they expect the session to have a TTY.

Use the "-t" option with SSH to make it allocate a pseudo-TTY even with non-interactive sessions. For example:

ssh -t hostname logname

I made a quick test and "ssh -t" seems to fix the problem.

MK
MK
skt_skt
Honored Contributor

Re: logname command do not remotely via ssh

it works, but return me a "connection closed"
Matti_Kurkela
Honored Contributor

Re: logname command do not remotely via ssh

> it works, but return me a "connection closed"

The "connection closed" message probably comes from your SSH client.

Perhaps the "logname" command at the target server outputs the correct answer, but without the LF character at the end? Then the "connection closed" message from the SSH client might overwrite the answer on your screen.

Or perhaps the end of the "logname" process at the target end triggers the tear-down of the connection, without making sure that all the data in various outgoing buffers has been transmitted? (This might be a SSH bug.)

I think I saw such behaviour once somewhere.

Please try these commands:

ssh -t hostname "logname; echo"

ssh -t hostname "logname; sleep 1"

One or both of these should fix the problem, no matter the cause.

MK
MK
skt_skt
Honored Contributor

Re: logname command do not remotely via ssh

both did not fix
"
root

Connection to hostname closed.

"
Matti_Kurkela
Honored Contributor
Solution

Re: logname command do not remotely via ssh

I think I misunderstood your problem: you want the command to return _only_ the output of the remote /usr/bin/logname and nothing else, right?

In that case, you'll need to add the -q option to ssh:

ssh -qt hostname logname

MK
MK