Finding your tty

dave driver mcvax!cel!dmd at uunet.uu.net
Wed Apr 26 07:56:58 AEST 1989


cstw01!meulenbr at uunet.uu.net (Frans Meulenbroeks) writes:
> Is there a way to detect your login tty?  

/usr/bin/tty will show the name of the tty for your current shell (RTFM
would have been good advice here), but if you specifically want to know
the tty on which you logged in, try setting an environment variable from
your .login file, i.e.

setenv LOGTTY `tty`

N.B. this will not work in a remote shell since the environment will not
be passed in this case due to a documented bug.

 Dave Driver (D^2)		dmd at cel.co.uk
 Crosfield Electronics		mcvax!ukc!uk.co.cel!dmd
 +44 442 230000 ext 3355

[[ RTFOP might be appropriate for this message (OP == "original posting"):
"ttyname(3) only gives me the name of the pty of the current window or
rlogin session."  He doesn't want the name of the tty associated with the
current window (which is what /usr/bin/tty gives you).  He wants the name
of the tty you originally (as in before starting suntools) logged in on.
To answer that question:  other than looking in utmp, the only way I can
think of doing it is walking back through the chain of parent process proc
structures to find the one for the login process and extract the
controlling terminal id from there.  Not a pleasant procedure.  --wnl ]]



More information about the Comp.sys.sun mailing list