Operating System - HP-UX
1822727 Members
3842 Online
109644 Solutions
New Discussion

C-Shell dynamic DISPLAY variable setting problem.

 
SOLVED
Go to solution
Gulam Mohiuddin
Regular Advisor

C-Shell dynamic DISPLAY variable setting problem.

We have hard coded the value of DISPLAY shell environment variable the in the .cshrc file. So my X Client works from the workstation who’s IP is there, but I if I try to work from any other workstation it doesn’t work.

Is there any way to dynamically set the IP address in DISPLAY variable in users login C-shell file .cshrc. This will help me to use my X client from any workstation.


Thanks,

Gula
Everyday Learning.
12 REPLIES 12
RAC_1
Honored Contributor

Re: C-Shell dynamic DISPLAY variable setting problem.

setenv DISPLAY=`getip "$(who -um|awk '{print NF}'")`:0.0

Anil
There is no substitute to HARDWORK
Gulam Mohiuddin
Regular Advisor

Re: C-Shell dynamic DISPLAY variable setting problem.

Thanks for your quick reply, but I got the following error:
{belfast- peel20} 23>>setenv DISPLAY=`getip "$(who -um|awk '{print NF}'")`:0.0
setenv: Too few arguments.
{belfast- peel20} 24>>


Gulam.
Everyday Learning.
RAC_1
Honored Contributor

Re: C-Shell dynamic DISPLAY variable setting problem.

setenv DISPLAY="`getip "$(who -um|awk '{print NF}')"`:0.0"

Syntax errors in earlier post. This should work.

Anil
There is no substitute to HARDWORK
A. Clay Stephenson
Acclaimed Contributor

Re: C-Shell dynamic DISPLAY variable setting problem.

It should be $NF rather than NF and you should also add some syntax to see if the hostname returned by who -um already has a ":0.0" appended before appending the ":0.0".
If it ain't broke, I can fix that.
Gulam Mohiuddin
Regular Advisor

Re: C-Shell dynamic DISPLAY variable setting problem.

Now it gives me syntax error:

{belfast- peel20} 35>>setenv DISPLAY="`getip "$(who -um|awk '{print NF}')"`:0.0"
Variable syntax.



Gulam
Everyday Learning.
Fred Ruffet
Honored Contributor

Re: C-Shell dynamic DISPLAY variable setting problem.

Doesn't know C shell a lot, but I believe you do not need = sign.

Now, as Clay said, if you already come with a XDMCP connection you may already have a :0.0 part. So you will have this : IP:0.0:0.0...

Solution may be something like that :
setenv DISPLAY "$(who -um|awk '{print $NF}'|cut -d : -f1)"

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Gulam Mohiuddin
Regular Advisor

Re: C-Shell dynamic DISPLAY variable setting problem.

Thanks, but still not working complains about some kind of Variable syntax:


{belfast- peel20} 17>>setenv DISPLAY "$(who -um|awk '{print $NF}'|cut -d : -f1)"
Variable syntax.


Thanks,

Gulam.
Everyday Learning.
Fred Ruffet
Honored Contributor

Re: C-Shell dynamic DISPLAY variable setting problem.

$() doesn't seem to work with csh.
# setenv DISPLAY "$(who -um|awk '{print $NF}'|cut -d : -f1)"
Variable syntax.
# setenv DISPLAY `who -um|awk '{print $NF}'|cut -d : -f1`

Second syntax works fine.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Gulam Mohiuddin
Regular Advisor

Re: C-Shell dynamic DISPLAY variable setting problem.

Thanks, last one works but it gives me hostname but I need the ip address instead.

Thnaks for your help.

Gulam.
Everyday Learning.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: C-Shell dynamic DISPLAY variable setting problem.

This should be a fairly bulletproof version but be warned all of these solutions fail if you are telnetting from an intermediate host. As long as you are directly connected to a particular host then this should work.

PS. C shell should be avoided like the plague.


set XX=`who -um | awk '{ split($NF,x,":"); print x[1] }'`
setenv DISPLAY `getip ${XX}`:0.0
unset XX

The intermediate variable XX simplifies the task and is undefined afterwards. This also takes care of the case where who -um return "hostname:0.0" or "hostname" or "10.1.2.3" or "10.1.2.3:0.0". If I got all the single quotes and backticks correct that should do you.


If it ain't broke, I can fix that.
Gulam Mohiuddin
Regular Advisor

Re: C-Shell dynamic DISPLAY variable setting problem.

Perfect, the last one worked very well.

Thanks all for your quick responses.

Regards,

Gulam.
Everyday Learning.
Sanjay_6
Honored Contributor

Re: C-Shell dynamic DISPLAY variable setting problem.

Hi,

Try

setenv DISPLAY `who am i -R |awk '{print $6}'|tr -d "()"`:0.0

There is a space after setenv and after DISPLAY.

Hope this helps.

Regds