Newsgroups: comp.unix.aix
Path: utzoo!utgpu!cunews!nrcnet0!cfd.di.nrc.ca!ng
From: ng@cfd.di.nrc.ca (Kai Ng)
Subject: Re: REMOTEHOST
Message-ID: <1991Mar22.201554.14530@nrcnet0.nrc.ca>
Sender: root@nrcnet0.nrc.ca (Operator)
Nntp-Posting-Host: cfd.di.nrc.ca
Reply-To: ng@cfd.di.nrc.ca
Organization: Informatics, National Research Council Canada
References: <1991Mar21.140213.8928@nrcnet0.nrc.ca> <1991Mar20.185405.5746@nrcnet0.nrc.ca> <6034@awdprime.UUCP> <6050@awdprime.UUCP>
Date: Fri, 22 Mar 91 20:15:54 GMT

In article <6050@awdprime.UUCP>, crow@waterloo.austin.ibm.com (David L. Crow) writes:
|> >In AIX/RS6000, is there a way to find out from where you are actually
|> >login'ed ?
|> 
|> # The first statement sets the TTY variable to be what is returned from
|> #    the 'tty' command without the /dev/  ie if tty returned '/dev/pty/3',
|> #    then all we want is 'pty/3'
|> # The second statement determines the display name for X to use.  I use
|> #    who to determine which machine we are coming from.  We grep on the tty
|> #    found in the previous step.  The awk gets the last item on the line
|> #    (i.e. the hostname).  The last item is of the form (host.domain...).  The
|> #    sed will strip the parenthesis and the domain leaving only the hostname.
|> #    Then we append the ":0" to make it the display name.
|> 
|> TTY=$(tty | sed 's/\/dev\///')
|> DISPLAY=$(who | grep $TTY | awk '{print $NF}' | sed
|> 's/(\([a-zA-Z0-9_]*\).*/\1/'):0
|> export TTY DISPLAY
|> 
|>  - This is only an exhibition, not a competition, so please....no wagering. -
|>   David Crow        (512) 823-4834    IBM VNET: dlcrow@austin
|>   AIX Systems Graphics Development    Internet: crow@waterloo.austin.ibm.com
|>  ------ Any opinions expressed are those of me and not of my employer. ------

This little script should works perfect and could be a perfect solution to me.
However, owing to the BUG in 'who' (which lists users who have already
logoff'ed and so in the list there are entries with same tty number), it
fails consistently. :-(

Is this bug fixed in 3003? We've just got the update tape and have not
applied it yet.

Thanks for the solution.

-- 
-----------------------------------------------------------------------------
Kai S. Ng                     Informatics, National Research Council Canada
INTERNET ng@cfd.di.nrc.ca     M-60 Montreal Road, Ottawa, Canada    K1A 0R6
BITNET   kain@nrcvm01.bitnet  VOICE (613) 993-0240       FAX (613) 954-2561
