Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to automatically set DISPLAY under CSH

807 views
Skip to first unread message

Ahmed Bouferguene

unread,
Nov 29, 1998, 3:00:00 AM11/29/98
to
Hello all,

Does anybody out there know how to set automatically the variable DISPLAY
to the name of the host I "came" from ? I know when using tcsh, one can
use the variable "REMOTEHOST" which is set by the environment. But in csh,
I do not see how can I get the name~(or IP) of the host I telneted from.

I have already tried "who -m" but this has two problems :
(1) It seems to not work on non-aix platforms~(like sgi's).
(2) The host name is trucated after 16 caracteres.

Any hints, pointers would be appreciated.


Thanks for your time and help.


--
Ahmed Bouferguene
-----------------------------------------------------------------------
Ce n'est pas par ce que les choses sont difficiles que nous n'osons pas
les faire. C'est parce que nous n'osons pas les faire qu'elles sont
difficiles.


Alan Hamilton

unread,
Dec 2, 1998, 3:00:00 AM12/2/98
to
On Sun, 29 Nov 1998 16:53:27 -0500, Ahmed Bouferguene
<bou...@cennas.nhmfl.gov> wrote:

>Hello all,
>
>Does anybody out there know how to set automatically the variable DISPLAY
>to the name of the host I "came" from ? I know when using tcsh, one can
>use the variable "REMOTEHOST" which is set by the environment. But in csh,
>I do not see how can I get the name~(or IP) of the host I telneted from.
>
>I have already tried "who -m" but this has two problems :
> (1) It seems to not work on non-aix platforms~(like sgi's).
> (2) The host name is trucated after 16 caracteres.
>
>Any hints, pointers would be appreciated.

The only place I'm aware that the full hostname is in
/etc/security/lastlog. This is root-readable only, though (and AIX
specific).

You can play with setenv NSORDER to prevent name resolution, but who
gets its hostname from utmp, which records the actual hostname rather
than the IP.

Justin McInnes

unread,
Dec 2, 1998, 3:00:00 AM12/2/98
to
This was pointed out to me by a really clever guy:
Never occoured to me to do it this way. (Thanks, Barry!)
The idea is to embed the DISPLAY in the TERM environment variable, which does
get passed thru rlogin and su sessions...

An example enhanced rlogin script, can also be used for su:

#!/bin/ksh
#
# /usr/local/bin/xrlogin
#
# A little bit of a security hole in the '$*'....customize as requried
#
if [[ -n $DISPLAY ]]
then
export TERM=$TERM^$DISPLAY
fi
rlogin $*

In your .profile on the 'remote' systems:

#
# Set DISPLAY if embedded in TERM, avoids setting a null DISPLAY
# The Fields are seperated by a ^ which is hardly used by anything.
#

if [[ -n $(echo $TERM | awk -F "^" '{print $2}') ]]
then
DISPLAY=$(echo $TERM | awk -F "^" '{print $2}')
TERM=$(echo $TERM | awk -F "^" '{print $1}')
fi

Zabra


Nicolas DE METZ-NOBLAT

unread,
Dec 2, 1998, 3:00:00 AM12/2/98
to
> On Sun, 29 Nov 1998 16:53:27 -0500, Ahmed Bouferguene
> <bou...@cennas.nhmfl.gov> wrote:
>
> >Hello all,
> >
> >Does anybody out there know how to set automatically the variable DISPLAY
> >to the name of the host I "came" from ? I know when using tcsh, one can
> >use the variable "REMOTEHOST" which is set by the environment. But in csh,
> >I do not see how can I get the name~(or IP) of the host I telneted from.
> >
> >I have already tried "who -m" but this has two problems :
> > (1) It seems to not work on non-aix platforms~(like sgi's).
> > (2) The host name is trucated after 16 caracteres.
> >
> >Any hints, pointers would be appreciated.

For both csh and tcsh, just put the followings in your .login file:

# Attempt to automatically setup DISPLAY environment variable
if ($?OS == 0) setenv OS `uname -s`
if ($?DISPLAY == 0) then
if (($TERM == "xterm") || ($TERM == "aixterm")|| ($TERM == "dtterm")) then
set y=""
if ( $OS == "OSF1" ) set y="-M"
if ( $OS == "HP-UX" ) set y="-R"
set x=`who $y am i | awk '{print substr($6,2,length($6)-2)}'`
switch ("$x")
case "*:*":
setenv DISPLAY $x
breaksw
default:
setenv DISPLAY $x\:0.0
endsw
unset x
unset y
echo DISPLAY assumed to be $DISPLAY
endif
else
echo DISPLAY previously set to $DISPLAY
endif


--
Nicolas de METZ-NOBLAT Phone: +41 22 76 72023 (direct)
CERN - PS division +41 79 201 3070
CH-1211 Geneva 23 Fax: +41 22 76 79145
Switzerland mailto:Nicolas.de....@cern.ch

Mathew A. Hennessy

unread,
Dec 2, 1998, 3:00:00 AM12/2/98
to
Very clever, though it will confuse hosts without your .profile
bits.. I tinkered with this (solaris, so perform commands in AIX first
and modify as needed):

#!/usr/bin/ksh
#
# this only works if you're in the same domain (or search path) as the
# remote system. Also, be sure that 'last' output is the same format.
# also, this thing can handle hostnames of only 14 or 15 letters..
#

# $LOGNAME should be standard..
# ETC is discarded.

last $LOGNAME|grep "still logged in"|head -1|\
while read USER TERM FROM ETC
do
if [ $TERM -ne "console" ] # in AIX, lft/hft?
then
DISP=`echo $FROM|cut -f1 -d"."`
export DISPLAY="${DISP}:0.0"
fi
done

#END
But I like your solution better.. ;)
--
Mathew A. Hennessy (henn...@thoughtcrime.com)
bleh.

0 new messages