Listing 1: Top-level shell script for bash and ksh shell script version
# Filename is display_s
#---------------------------------------------------------------
# This file exports the proper display name so the user does not
# have too. All that is needed is to
# .display_s in .profile for bash and ksh
#
# This script works for both bash, and ksh.
# Any changes should take that into consideration.
# Test to see if display is set.
if test $DISPLAY ;then
echo "DISPLAY= \"$DISPLAY\""
#if it is set don't mess with it!
else
dir_tmp=/bin/display
dir_start=`pwd`
uname_var=`uname`
cd $dir_tmp
# get the tty you login on
tty_var=`tty`
# do a who to see where you came from
if test "$uname_var" = "SunOS"
then
# SUN-OS
#echo "SUN-OS"
who > $dir_tmp/who_file
else
if test "$uname_var" = "Linux"
then
# Linux
# echo "Linux"
who > $dir_tmp/who_file
else
if test "$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
fi
fi
fi
# store in a file
tty > $dir_tmp/tty_file
# kill the /dev/ before the tty terminal
tty_search_var=`sed -e 's/\/dev\///' $dir_tmp/tty_file`
# search for the terminal we came in on
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
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
real_hostname=`cat $dir_tmp/real_hostname_file0`
# if noname set to default of the machine you are logged into
if test "$real_hostname" = ""
then
real_hostname=":0.0"
fi
# print the global display for all to see
echo "export DISPLAY=$real_hostname"
# export the global display name
export DISPLAY=$real_hostname
cd $dir_start
fi
# End of File
|