Operating System - HP-UX
1845298 Members
4705 Online
110244 Solutions
New Discussion

Problem with set_display script

 
Robert Binkley
Advisor

Problem with set_display script

Even with xhost + the below script still will not export the system display:


set_display.ksh

#!/sbin/ksh
#* set_display.ksh
# %W% %G% retrieved at %H% %T%
# *************************************************************************
# * Program Name: set_display *
# * Date Written: June 30, 1998 *
# * Written By : Robert Binkley*
# *************************************************************************
# * This script will set the display environment variable for this user *
# * by determining the terminal type, etc. *
# * NOTE!!! You must run this command with the ". command" structure or *
# * the environment setting will not be defined for your session when this*
# * script terminates. *
# *************************************************************************
# * Revision History: *
# * *
# * 09/17/98 R.B. Added comment line to incorporate SCCS source control. *
# * Added some general aliases at the bottom. *
# * *
# * 04/30/00 R.B. Changed argument in finger command to get system name *
# * due to move from Dec UNIX to Sun UNIX. *
# * *
# * 06/22/01 Robert Binkley Modified to work with AIX *
# *************************************************************************
echo

# Determine the process user id from the system. This will get the
# parent user even if su has been used.
USER_NAME=`who am i | awk '{ print $1 }'`
echo "Setting USER_NAME to" $USER_NAME
export USER_NAME

# Determine the terminal id for the parent user's process.
TTY_NAME=`who am i | awk '{ print $2 }'`
echo "Setting TTY_NAME to" $TTY_NAME
export TTY_NAME

# Determine the host machine for this user and terminal id. This is used
# to assign the DISPLAY variable for X-based application stuff.
HOST_MACHINE=`who am i | awk -F'[\t()]' '{ print $2 }'`

case "$HOST_MACHINE" in
[a-zA-Z]* )
HOST_MACHINE=`who am i | awk -F'[\t()\.]' '{ print $2":0.0" }'`
;;
[0-9]* )
HOST_MACHINE="$HOST_MACHINE:0.0"
;;
esac

echo "Setting DISPLAY to $HOST_MACHINE"
#export DISPLAY=$HOST_MACHINE

# Add this alias function for some general "coolness".
alias ll='ls -l'
alias lst='ls -ltr'

echo


4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor

Re: Problem with set_display script

I assume you have commented out the export DISPLAY= statement for some reason. Of course, it can't work like this but I suspect your real problem is that you are invoking the script from another scripts and sure enough when you get back to the parent, DISPLAY is not set. A child is never allowed to alter the enviroment of a parent.

However, what you could do is source this script using the . (dot) operator to incude this script as part of the foreground process. In this case, make sure that the sourced file has no exit or return statements because you will instantly exit the foreground process.
If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: Problem with set_display script

Might this help?

DISPLAY=$(who -m -u | awk '{print $8}'):0.0
export DISPLAY

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Patrick Wallek
Honored Contributor

Re: Problem with set_display script

I think your problem is your use of the 'who am i'. The way you are using it, it will return nothing, because the machine you are connecting from is not displayed. Try substituting 'who am i -R' in your script and see if that works better.
Bill Hassell
Honored Contributor

Re: Problem with set_display script

Also note that if you simply run the scriopt, DISPLAY will be set within the script (which is interpreted by a sub-shell) and the everything is forgotten when you return back to the parent. You either include this code in /etc/profile or always run the script using the dot command:

. myScript

The dot command tells the current shell to read and interpret the commands locally rather than n a sub-shell.


Bill Hassell, sysadmin