Listing 2: Top level shell script for csh and tcsh shell script version
# Filename is display_s.csh
#---------------------------------------------------------------
# This file exports the proper display name so the user does not
# have too. All that is needed is to
# source display_s.csh in /usr/local/lib/Cshrc-source -- SUN-OS 4.1.2
# source display_s.csh in /etc/csh.login -- HP-UX 10.0
# or
# source display_s.csh in .cshrc for csh
#
# This script works for both csh, and tcsh.
# Any changes should take that into consideration.
#
# The next three statements are a patch because csh does not like it
# when a var like DISPLAY is never set and you check it's contents.
set NULL=""
setenv DISPLAY $NULL
#echo $DISPLAY
set display_var=`echo $DISPLAY`
# DISPLAY variable not set kills this next statement and hangs csh
# Test to see if display is set.
if ( $display_var != "" ) then
echo "DISPLAY= \"$display_var\""
#if it is set don't mess with it!
else
set dir_tmp=/bin/display
set dir_start=`pwd`
set uname_var=`uname`
cd $dir_tmp
# get the tty you login on
set tty_var=`tty`
## do a who to see where you came from
if ( "$uname_var" == "SunOS" ) then
# SUN-OS
#echo "SUN-OS"
who > $dir_tmp/who_file
else
if ( "$uname_var" == "Linux" ) then
# Linux
# echo "Linux"
who > $dir_tmp/who_file
else
if ( "$uname_var" == "HP-UX" ) then
# HP-UX
# echo "HP-UX"
who -R> $dir_tmp/who_file
else
# echo "What kind of OS is this?"
who > $dir_tmp/who_file
endif
endif
endif
# store in a file
tty > $dir_tmp/tty_file
# kill the /dev/ before the tty terminal
set tty_search_var=`sed -e 's/\/dev\///' $dir_tmp/tty_file`
# search for the terminal we came in on
set tty_search=`grep "$tty_search_var " $dir_tmp/who_file >
$dir_tmp/tty_search_file`
#debug
#echo $tty_search
# get the 6th column grep the who command
set real_hostname=`awk '{ print $6 }' $dir_tmp/tty_search_file >
$dir_tmp/real_hostname_file`
#debug
#echo $real_hostname
# straighten out the real hostname
sed -f edit_real.sed $dir_tmp/real_hostname_file >
$dir_tmp/real_hostname_file0
set real_hostname=`cat $dir_tmp/real_hostname_file0`
# if noname set to default of the machine you are logged into
if ( "$real_hostname" == "" ) then
set real_hostname=":0.0"
endif
# print the global display for all to see
echo "setenv DISPLAY $real_hostname"
# export the global display name
setenv DISPLAY $real_hostname
cd $dir_start
endif
# End of File
|