mwette@csi.jpl.nasa.gov (Matt Wette) (04/03/91)
In article <1991Apr3.144934.13473@cbnewsc.att.com>, dalka@cbnewsc.att.com (kenneth.j.dalka) writes: |> I'm using an X windowing terminal with a UNIX system V machine and I'd like |> to set the DISPLAY variable automatically from a shell script (or C program). |> The problem is that I'd like to make it terminal independent. Rather that |> setting some pre determined IP address in my .profile, I'd like to be able |> to walk down the hall and log on with some other terminal if need be. The |> only way I can see that this would work is if I could somehow ask UNIX |> what my IP address is. It must know because I can login and talk to unix |> before I get to X. If UNIX can send characters back to me, then it knows |> where I am. But I can't find any place in UNIX where the info is stored. I assume what the author wants is to get his DISPLAY variable set automatically on rlogin's. Enclosed is the solution I use to for this problem. Basically, I remote login with a "rlogn" shell script which sets the TERM variable to <term>@<display-machine> and xhost's the new host if DISPLAY is set, then executes /usr/ucb/rlogin. In my .cshrc file I include code which looks for '@' in the TERM variable and if it exists strips off the first part for the real TERM variable and the second part for the DISPLAY variable. Matt #! /bin/sh # To extract, remove mail header lines and type "sh filename" echo x - rlogn sed -e 's/^X//' > rlogn << '!FaR!OuT!' X#!/bin/sh Xswitches="" Xhostarg="" Xwhile [ "$*" ]; do X case $1 in X -L) X switches="$switches $1"; shift ;; X -8) X switches="$switches $1"; shift ;; X -e*) X switches="$switches $1"; shift ;; X -l) X switches="$switches $1 $2"; shift; shift ;; X -*) X echo 'unknown switch: quitting.'; exit 1 ;; X *) X hostarg=$1; shift ;; X esac Xdone Xif [ "$DISPLAY" != "" ]; then X host=`echo $DISPLAY | sed -e 's/:.*//'` X TERM=${TERM}@${host} X export TERM X if [ "`hostname`" = "$host" ]; then X xhost $hostarg X else X rsh $host xhost $hostarg X fi Xfi Xexec /usr/ucb/rlogin $switches $hostarg X# !FaR!OuT! chmod ugo+x rlogn echo x - cshrc.display sed -e 's/^X//' > cshrc.display << '!FaR!OuT!' X# -- set display -- Xif ( "$TERM" =~ *@* ) then X setenv TERM `echo $term | sed -e 's/@.*//'` X setenv DISPLAY `echo $term | sed 's/.*@//'`:0.0 Xendif !FaR!OuT! exit -- _________________________________________________________________ Matthew R. Wette | Jet Propulsion Laboratory, 198-326 mwette@csi.jpl.nasa.gov | 4800 Oak Grove Dr, Pasadena,CA 91109 -----------------------------------------------------------------