1832869 Members
7859 Online
110048 Solutions
New Discussion

Re: Shell Script

 
SOLVED
Go to solution
Vasudevan MV
Frequent Advisor

Shell Script

Hi,

Can any one tell me, is there any command to get the full hostname other than nslookup?. When I type "echo $DISPLAY", it gives "xyz:10.0", but I need to export the DISPLAY variable to xyz.tt.nt.com:10.0 (with the full hostname).

Thanks
Vasu


10 REPLIES 10
Paula J Frazer-Campbell
Honored Contributor

Re: Shell Script

Hi

Will hostname give you what you want?

Paula
If you can spell SysAdmin then you is one - anon
PIYUSH D. PATEL
Honored Contributor
Solution

Re: Shell Script

Hi,

Apart from nslookup....

Use #hostname - that will give u the hostname
eg. node1

then use #domainname - that will give you the domain name
eg xyz.com

Hence use node1.xyz.com

HTH,
Piyush
Peter Kloetgen
Esteemed Contributor

Re: Shell Script

Hi Vasudevan,

you can put the full qualified domain name together with command substitution and a variable:

variable=`hostname``domainname`
(use backticks here everywhere to get it work)
echo $var

--> will deliver you the FQDN of that host

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Miguel Covas
Advisor

Re: Shell Script

It seems that nslookup is going to be replaced by host. But since there is no host command in HPUX I think that you have to stick to nslookup. nslookup will search DNS but you can configure it to search on /etc/hosts if you need that.

Otherwise is unlikely that you get a standard way to get the full qualified host name or address. My experience is that usually domainname gives you blank. Admin seldom care to initialize it properly and in these times of LDAP, yp is not so popular...

If you need to inform DISPLAY I think that combining hostname and nslookup will do the job. Otherwise you can inspect /etc/hosts, but you can end up looking up a mere 127.0.0.1 localhost.

Since there is no host command, my advice is
(sorry) nslookup
Helen French
Honored Contributor

Re: Shell Script

If the FQDN has been set at the last ( in the 3rd column), then this would display it:

# cat /etc/hosts | grep `hostname` | awk '{print $3}'

just a thought ..
Life is a promise, fulfill it!
Christopher McCray_1
Honored Contributor

Re: Shell Script

Hello,

It won't give you the full output, but

# who -mT

should do the trick

Chris
It wasn't me!!!!
MANOJ SRIVASTAVA
Honored Contributor

Re: Shell Script

Hi



hsotname is the command.



Manoj Srivastava
Christopher McCray_1
Honored Contributor

Re: Shell Script

Hello again

Here is what I put into scripts for exporting displays:

export DISPLAY=`who -mT | awk '{print $9}'`:0.0

Hope this helps

Chris
It wasn't me!!!!
Bill Hassell
Honored Contributor

Re: Shell Script

Whether you can see the domain name or not is very dependent on whether you use DNS, NIS or /etc/hosts for name resolution. A more general solution is to use the IP address (which takes care of everything):

DISPLAY=12.34.56.78:0.0

By setting the IP address, you are assured of zero problems with name resolution.


Bill Hassell, sysadmin
Glenn L. Stewart
Frequent Advisor

Re: Shell Script

I agree with the above post. You can simply use the ip if you can't use nslookup.

Try the following as a slightly more robust solution.

HOST=$(hostname)
CURRENT_IP=$(getip $HOST)
export DISPLAY=$CURRENT_IP:0.0

Of course these can be combined into one line...

Curious: What can't you use DNS?

If DNS cannot be used, you may try placing host in question in the /etc/hosts, ensuring that files is before DNS in your nsswitch.conf

Glenn