harald@itk.unit.no (02/08/90)
Enclosed is a script which does remote X11 commands AND sets DISPLAY and TERM. It works fine for X-terminals too... Comments are welcome. Regards, Harald Backer //////////////////////////////////////////////////////////////////////// / Harald Backer / harald@itk.unit.no / / SINTEF Automatic Control / (+47 7) 594375 Switchboard / / The Norwegian Institute of Technology / (+47 7) 594399 Fax / / N-7034 Trondheim / / / NORWAY / / //////////////////////////////////////////////////////////////////////// ------------------------- cut here ----------------------------------- #! /bin/sh # # xon: run local xterm and rlogin on remote host # or # start an X11 client on remote host # # Runs the given command on another host with $DISPLAY and $TERM set # in the environment. Is dependant on a patch in .login (.profile) # when you run a local xterm: # # if ($TERM =~ xterm.*) then # setenv DISPLAY `echo $TERM | sed 's/xt[^.]*\.//'` # setenv TERM xterm # endif # # # Does an xhost to allow access to the other host. # Xon is very careful not to leave any extra processes waiting # around on either machine for the client to exit. All inputs # and outputs are redirected to /dev/null. # If the given command starts with "xterm", it adds the arguments # "-name xterm@$hostname" # where $hostname is the name of the remote host. This allows # you to customize your server's xrdb database to set attributes, # such as the window color, based on the name of remote host. # # Based on xon from X11R4/contrib/clients/scripts/xon.sh # Modified 900207 harald@itk.unit.no : ${DISPLAY?"environment variable DISPLAY not set"} #defaults user= case $# in 0) echo " usage: $0 host [-l user] which invokes a LOCAL xterm and logs you in on the remote host or $0 host [cmd [args]] which executes cmd at remote host " 1>&2; exit 1;; esac # get the host name host="$1"; shift name="$host" # give remote host access to X server xhost +$host > /dev/null 2>&1 # get a "good" $DISPLAY variable # running on a console ? thishost=`hostname` server="`echo $DISPLAY | sed \"s/^unix:/${thishost}:/\"`" # including domainname domainname=`/bin/domainname` server="`echo $server | sed \"s/^\([^.]*\):/\1\.${domainname}:/\"`" # get user name if [ $# -ge 2 -a "$1" = "-l" ]; then name="$2@$name" user="$1 $2"; shift; shift fi if [ $# -eq 0 ]; then # invoke a LOCAL xterm and do a rlogin # modify $TERM and patch ((c) rlk@THINK.COM) it in .login like this: # if ($TERM =~ xterm.*) then # setenv DISPLAY `echo $TERM | sed 's/xt[^.]*\.//'` # setenv TERM xterm # endif # exec xterm -title $name -name $name -e env TERM=xterm.$server rlogin $host $user & else command=$1; shift if [ "$command" = "xterm" ]; then command="$command -name xterm@$host" fi if [ $# -ge 1 ]; then command="$command $@" fi exec rsh $host -n exec env DISPLAY=$server TERM=xterm PATH=$PATH "$command < /dev/null >& /dev/null" & fi exit 0