DOCUMENT ID: 1039-02 SYNOPSIS: How to determine local hostname while logged into remote host OS RELEASE: PRODUCT: Solaris KEYWORDS: local hostname log remote host X11 openwindows who DESCRIPTION: The local host name is useful when using X11 or openwindows applications requiring the local display. The environmental variable "DISPLAY" is set using a script file. SOLUTION: The "who" command, in various forms, displays useful data including the host of origin (local host). A typical who display might be: joe pts/22 jun 31 20:15 (remote) By employing a series of piped commands the local host name may be derived. The series of commands may possibly be improved, however this method is functional. Once the local host name is determined it may be utilized in expressions to set the "DISPLAY" environmental variable. The most likely place to set the variable is .profile or .login during shell startup. This method is intended for use with first generation remote hosts, i.e., one host connection rather than local_host->to remote->to remote. The script may be used without regard to whether a remote login is in progress. "Who" will return five fields on a local login and six fields on remote login. # !/bin/sh # xtty=`tty | cut -c6-15` h2=`who | grep $xtty | tr -d '()'` xc=`echo $h2 | wc -w` if [ $xc = 6 ]; then echo $h2 | awk '{ print $6 }' else hostname fi DATE APPROVED: 09/12/95