Summary for Remote Display Server

From: Zhang, Weixing <Weixing.Zhang_at_stjude.org>
Date: Wed, 21 Jun 2000 15:48:34 -0500

Hi Charles,
        After I read all the suggestions from those people who replied to my message
and some testing, I came up with the following solution. These lines can be put in my
.login file to get the remote display server.

set server=`last -1 $USER|awk '{print $3}'`
setenv DISPLAY $server":0.0"

I think many other people are also insterested in this subject. I am attaching all the email that
I received. Hope these are helpful to you.

Weixing

****************************************************************************
*****************
I use the following line in my .login script on the SUN to set the
server to the name of the remote computer from which I logged in:

 set server=`finger jmw|tail -1|awk '/On since/ {print $NF}'`

where jmw is my login name.
****************************************************************************
*****************
Basically, the information you want is contained in the output from
typing 'who am i', however the format is a bit variable and it also
contains some information you don't want. One of our IT guys here
tidied this up for us a few years ago in a shell script called
'fromwhere' (copy attached). By hacking this (for example substituting
your own domain names in place of dur.ac.uk, etc) you should be able to
get it to work. I use this to set the display variable in some of my
.login scripts and it works fine.

Good luck!

#!/bin/csh -f
#$Header: /home/jeeves/package/pageprnt/scripts/bin/RCS/fromwhere,v 1.2
1995/07/20 11:03:34 pageprnt Exp pageprnt $
# Barry Cornelius, University of Durham, July 1994

# The output from 'who am i' is dependent on the utmp records.
# These are sometimes inaccurate on Solaris 2.x machines.
set who = `who am i`

# The text at the end of the output from 'who am i' often contains
# the IP address of the machine in parentheses. So set the variable
# address to this text if it's there or to 'unknown' if it isn't.
set address = `expr "$who" : '.*(\(.*\))' \| unknown`

# The text that was inside the parentheses is sometimes truncated if it is
# too long. This switch statement reinstates the full IP address.
switch ( $address )
   case *.dur.ac.uk:
      breaksw
   case *.dur.ac*:
      set machine = `expr "$address" : '\(.*\).dur.ac'`
      set address = $machine.dur.ac.uk
      breaksw
   default:
      breaksw
endsw
echo $address
****************************************************************************
*****
This is the solution I came up with. If you get a better one would you
please
pass it along to me.


  set loginterm=`ps|tail -1|awk '{print $2}'`
  set loginserver=`who |grep $loginterm| awk -F"(" '{print $2}' | awk -F")"
'{print $1}'`
  setenv DISPLAY $loginserver":0.0"

First line get the terminal ID for your last process in that shell, so if
this
is done in .login it't the terminal ID for your login shell.

The second line gets your login computer from the who list by findind your
terminal ID.
****************************************************************************
*********
Don't blame Sun for this, Varian just hasn't worked very hard at this. To
set display automatically put this in your csh login script at the group
level of the VNMR server. Please note that this is the code we use here to
do just what you want, BUT THIS MAY NEED SOME EDITING TO WORK FOR YOU.
Specifically you probably want to cut out the Openwin startup and all parts
associated with .xol-init.

       This uses the short form of the client name (the same as is seen in
last). You may need to use the FQDN so add the fields to the CLIENT as
needed (that is why it is braced{}).

To set the terminal type automatically you need to edit the VNMR servers
.login.


SAMPLE CODE:
*********************************

#First case new logon console
if ( $TERM != sun-cmd ) then
        stty werase ^h
endif

 if ( `tty` == "/dev/console" && $TERM == "sun" ) then

        echo ""
        echo -n "Starting OpenWindows in 5 seconds (type Control-C to
interrupt)"
        sleep 5
        echo ""
        $OPENWINHOME/bin/openwin
        clear # get rid of annoying cursor rectangle
        logout # logout after leaving windows system
#Now for network client case
 else if ( $TERM == "network" ) then
        if ( $?DISPLAY <= 0 ) then
           set last = ` last $user | head -1 `
           setenv CLIENT $last[3]
           if ( $?last != 0 ) then
             setenv DISPLAY ${CLIENT}:0
           endif
        endif
        if ( $?DISPLAY != 0 ) then
           echo Starting Openwindow tools, using $DISPLAY \(hit control-C
to abort \)
           sleep 5
           echo Too late....
           if ( -x $HOME/.xol-init ) then
              $HOME/.xol-init
           else
              /usr/local/bin/.xol-init
           endif
           echo "Openwindow tools being started. Please be patient."
        endif

 else if ( $TERM =~ *xterm* || $TERM == sun-cmd || $TERM =~ *vt* ) then
        if ( $?DISPLAY == 0 ) then
           set last = ` last $user | head -1 | cut -d"." -f1 | sed -e "s/\
*//g" `
           echo $last
           if ( $?last <= 0 ) then
             setenv CLIENT $last[3]
             setenv DISPLAY ${CLIENT}:0
           endif
         endif
         #DISPLAY is set so start openwindows tools
         if ( $?DISPLAY != 0 && $TERM == sun-cmd ) then
            echo Starting Openwindow tools, using $DISPLAY \(hit control-C
to abort \)
            sleep 5
            if ( -x $HOME/.xol-init ) then
               $HOME/.xol-init
            else
               /usr/local/bin/.xol-init
            endif
            echo "Openwindow tools being started. Please be patient."
         endif
 else if ( $?TERM <= 0 ) then
        set noglob
        eval `tset -s`
        unset noglob
 endif
 if ( $?TERM <= 0 ) then
      setenv TERM vt220
      set term = vt220
  endif


****************************************************************************
********
There's really no easy or general way to do this. I think you've already
found a decent way to approach it, by examining the results of the "last" or
"who" command. You'd also need to use the "tty" command which prints the
name of the pseudo-terminal you're logged in on, for example "/dev/pts/6".
Here's how you might do all this:

set pty = `tty | sed -e 's:/dev/::'`

set remotehost = `who | egrep $pty | awk '{ len=length($NF); print
substr($NF,2,len-2); exit }'`
or:
set remotehost = `last $USER | egrep $pty | awk '{ print $3; exit }'`

set DISPLAY = ${remotehost}:0.0

The sed command removes "/dev/" from the front of the terminal name. The
awk command selects the name of the remote host, and in the case of the
"who" command, removes the parentheses that who puts around it.

You're going to have to fiddle with this to get it to work the way you want.
You may need to add absolute paths to some of the commands. The tty command
will fail for some kinds of sessions, for example "rsh" sessions.
****************************************************************************
****







> -----Original Message-----
> From: Charles G. Fry [SMTP:fry_at_bert.chem.wisc.edu]
> Sent: Wednesday, June 21, 2000 2:08 PM
> To: Zhang, Weixing
> Subject: Re: Remote Display Server
>
> Weixing,
>
> I would appreciate seeing a summary, or simple listing if easier,
> of the message you got, or solution you came up with. I have
> tried this a number of times myself on our Sun's, with no solution
> yet. I do not allow finger to run however; that's a definite
> security hole on unix systems that are not behind a firewall.
> I don't think people can break in via finger, but they can get a
> lot of info useful to crackers.
>
> Thanks,
> Charlie
>
>
>
> At 11:59 AM 6/21/00 -0500, you wrote:
> >I really appreciate the help from those people who replied my message.
> In
> >fact, there are
> >many ways to solve this problem. The remote server can be extracted from
> >the output of
> >one of the following commands.
> >
> >finger, who am i, who, last
> >
> >Weixing
> >
> >
>
>
> ----------------------------------------------------------
> Charles G. Fry, Ph.D. Tel: (608)262-3182
> Director, MR Facility Fax: (608)262-0381
> Chem. Dept., Univ. Wisconsin
> Madison, WI 53706 USA email: fry_at_chem.wisc.edu
> ----------------------------------------------------------
Received on Wed Jun 21 2000 - 16:53:57 MST

This archive was generated by hypermail 2.4.0 : Sat Jun 03 2023 - 15:53:26 MST