Operating System - HP-UX
1753774 Members
6904 Online
108799 Solutions
New Discussion юеВ

can't set DISPLAY with hostname

 
SOLVED
Go to solution
sharathkv25
Frequent Advisor

can't set DISPLAY with hostname

Hi,

I can't bring up xclock if I set the DISPLAy with hostname.
i,e:
export DISPLAY=`hostname`:0.0

I can bring up xclock if I set to IP Address
i,e:
export DISPLAY=XXX.XXX.X.X:0.0

Any idea?
10 REPLIES 10
John Kittel
Trusted Contributor

Re: can't set DISPLAY with hostname

try qualifying hostname, e.g. myhost.mydomain.com ( or whatever)

can you nslookup "hostname" ?
A. Clay Stephenson
Acclaimed Contributor

Re: can't set DISPLAY with hostname

From the point of view of the host that is trying to execute xclock, can the hostname be resolved?
If it ain't broke, I can fix that.
Bill Hassell
Honored Contributor
Solution

Re: can't set DISPLAY with hostname

This is not a DISPLAY problem, it is a resolver problem. The resolver is a fancy name for the conversion of numeric IP addresses into a more human-compatible name. If you are using a DNS server, all sorts of difficult situations will occur (due to DNS maintenance or lack thereof), so the rule is to tell HP-UX to look in /etc/hosts first, then ask DNS. To do this, edit the /etc/nsswitch.conf file and change the line with hosts: to read like this:

hosts: files [NOTFOUND=continue] dns

If you don't have /etc/nsswitch.conf, create one with:

cp /etc/nsswitch.files /etc/nsswitch.conf
chmod 644 /etc/nsswitch.conf

then edit the new file as mentioned.

The sole purpose of /etc/hosts and DNS is to associate an IP address and one or more names together. Eliminate all the DNS politics by specifying /etc/hosts first in the nsswitch.conf file.


Bill Hassell, sysadmin
skt_skt
Honored Contributor

Re: can't set DISPLAY with hostname

For HP-UX 11.11 . Here is the right format.I have observed in couple of servers that the /etc/nsswitch.files looks different.

adedd16p:root [/etc] cat nsswitch.conf
#
# /etc/nsswitch.files:
#
# @(#)B.11.11_LR
#
# An example file that could be copied over to /etc/nsswitch.conf; it
# does not use any name services.
#
passwd: files
group: files
hosts: files [NOTFOUND=continue] dns
services: files
networks: files
protocols: files
rpc: files
publickey: files
netgroup: files
automount: files
aliases: files
sharathkv25
Frequent Advisor

Re: can't set DISPLAY with hostname

Do i need to reboot server?

Thanks
A. Clay Stephenson
Acclaimed Contributor

Re: can't set DISPLAY with hostname

No, as soon as you have fixed hostname resolution, the changes take place immediately (or more accurately, processes started after the changes will resolve correctly); those processes that were running before the resolver fix MIGHT be fixed without restarting but probably will not be. It depends upon the nature of your fix and the caching.
If it ain't broke, I can fix that.
sharathkv25
Frequent Advisor

Re: can't set DISPLAY with hostname

Hi,

The issue is not fixed.
---------------------------------------------
$ export DISPLAY=`hostname`:0.0
$
$ xclock &
[1] 11821
$ Error: Can't open display: dev1:0.0

[1] + Done(1) xclock &
----------------------------------------------

I followed the steps suggetsed by Bill Hassel, yet I not able to bring up the GUI.

This is quite important since a lot of our scripts use hostname in DISPLAY & they would be broken due to this small issue.

Thanks
Bill Hassell
Honored Contributor

Re: can't set DISPLAY with hostname

> The issue is not fixed.
> $ export DISPLAY=`hostname`:0.0

$ Error: Can't open display: dev1:0.0

Well, let's start by asking where your display device is located. The above works just fine on a local workstation with a graphics card, mouse and keyboard. When you run the hostname command on the HP-UX computer, it will return it's hostname, in this case, dev1. My guess is that you are not using the workstation's display but instead you are using a Linux box or a PC running an Xwindow emulator. And the purpose of the DISPLAY variable is to tell Xwindows where to send the graphics images. In other words, DISPLAY must be set to your display device's IP address.

So while the construct: export DISPLAY=`hostname`:0.0 will work just fine on the local workstation, re-displaying the image on some other computer requires a totally different construct like this:

export DISPLAY=$(who -muR | awk '{print $NF}');0.0

Run the command: who -muR and you'll see that it reports your local computer's IP address or hostname, which is what you want. When you set DISPLAY=someIPaddress, it works because you did not set it to the HP-UX box address, you set it to the PC or Linux box address. The who -muR command will provide that detail for you automatically. The scripts that have `hostname` coded will all have to change or the users must always run the script sitting in from of the HP-UX workstation.


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: can't set DISPLAY with hostname

> The issue is not fixed.
> $ export DISPLAY=`hostname`:0.0

$ Error: Can't open display: dev1:0.0

Well, let's start by asking where your display device is located. The above works just fine on a local workstation with a graphics card, mouse and keyboard. When you run the hostname command on the HP-UX computer, it will return it's hostname, in this case, dev1. My guess is that you are not using the workstation's display but instead you are using a Linux box or a PC running an Xwindow emulator. And the purpose of the DISPLAY variable is to tell Xwindows where to send the graphics images. In other words, DISPLAY must be set to your display device's IP address.

So while the construct: export DISPLAY=`hostname`:0.0 will work just fine on the local workstation, re-displaying the image on some other computer requires a totally different construct like this:

export DISPLAY=$(who -muR | awk '{print $NF}'):0.0

Run the command: who -muR and you'll see that it reports your local computer's IP address or hostname, which is what you want. When you set DISPLAY=someIPaddress, it works because you did not set it to the HP-UX box address, you set it to the PC or Linux box address. The who -muR command will provide that detail for you automatically. The scripts that have `hostname` coded will all have to change or the users must always run the script sitting in from of the HP-UX workstation.


Bill Hassell, sysadmin