Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting DISPLAY variable automatically

Status
Not open for further replies.

stackdump

Technical User
Sep 21, 2004
278
GB
Hi all,

Im using a network where PC's connect via Exceed to Unix hosts. Users have to set the DISPLAY variable and I thought I could make this automatic. I wrote the script below invoked (in the .cshrc). This works ok, even when jumping to other machines mid session with rlogin, ssh etc. But this looks just looks excessive, There must be an easier way to do this? any ideas?


set DISPSESSION=`(tty|sed s^/dev/^^)`
setenv DISPLAYNODE `(who | grep "$DISPSESSION " | awk '{print $6}'|sed 's/(//'|sed 's/)//')`
# Check that the host has a "." in it (either an IP address, .dom or 0.0)
if (($DISPLAYNODE != "") && (`echo $DISPLAYNODE | grep -c "\."` != 0)) then
rm -f ~/.DISPLAY
if (`echo $DISPLAYNODE | grep -c "0.0"` == 0) then
# Add :0.0 to end of IP address
echo "$DISPLAYNODE"":0.0" > ~/.DISPLAY
else
# Dont need 0.0 since already present
echo "$DISPLAYNODE" > ~/.DISPLAY
endif
endif

if (-f ~/.DISPLAY) then setenv DISPLAY `cat ~/.DISPLAY`

 
you should be able to connect to the unix hosts with:

ssh -X user@host

so if you have an X server in the PC, the DISPLAY environment var will be set automatically.

Example: try cygwin and/or Xmanager with putty.

Cheers.
 

ok, thanks. I'll try that out. I also just found $REMOTEHOST which carries the required information in most circumstances. So a simpler script becomes;

if ((`echo $REMOTEHOST | grep -c "\."` != 0) || (`echo $REMOTEHOST | grep -c "semnet"` != 0)) then
setenv DISPLAY $REMOTEHOST":0.0"
else
# do it the old way
endif

 

Thats for sure!

Ive certainly been there and done that a few too many times. For stupid reasons Ive opened up a whole can of worms unnecessarily and ended up working all night to repair what was never broken!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top