Operating System - HP-UX
1753637 Members
5816 Online
108798 Solutions
New Discussion юеВ

Display DNS names as a prompt

 
SOLVED
Go to solution
Anuraag
Occasional Advisor

Display DNS names as a prompt

Hi,

I want the DNS name to get printed in the prompt of the HP-UX machine.
If the dns name of the machine is a.it.com then the prompt should look like

a.it.com >
9 REPLIES 9
Peter Godron
Honored Contributor

Re: Display DNS names as a prompt

Hi,
and welcome to the forums !

You can set with:
export PS1='a.it.com >'


Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
James R. Ferguson
Acclaimed Contributor

Re: Display DNS names as a prompt

Hi:

If you add this to your '.profile' (Posix or Korn) shell assumed, you will display the server hostname.

# PS1=`hostname`" # "

Of course, change '#' to '$' for non-root accounts to differentiate them.

Regards!

...JRF...
Patrick Wallek
Honored Contributor
Solution

Re: Display DNS names as a prompt

Try this in your .profile or the /etc/profile.

I prefer to differentiate a normal user prompt (usually a $) from the root prompt (usually a #).

HOST=$(nslookup $(hostname) | grep Name: | awk '{print $2}'
export PS1="${HOST} >"
Patrick Wallek
Honored Contributor

Re: Display DNS names as a prompt

Oops....

I missed a closing ) in my command above. It should be:

HOST=$(nslookup $(hostname) | grep Name: | awk '{print $2}')
Anuraag
Occasional Advisor

Re: Display DNS names as a prompt

Thanks Patrick,

I am able to get that now. i just wanted to know one more thing. In TRU64,

export PS1="`uname -n >"

solves the problem. It doesnt work the same way in HP-UX?
Anuraag
Occasional Advisor

Re: Display DNS names as a prompt

Is it not possible by just using a single unix command to get this?
Patrick Wallek
Honored Contributor

Re: Display DNS names as a prompt

You said you wanted the "DNS NAME" for the prompt.

In my mind the DNS name is different from the hostname or 'uname -n' output.

Your example shows the fully qualified 'a.it.com' which you typically don't see from 'uname -n' or hostname.

So, which do you want?

If you just want the 'uname -n' ouput you can try:

export PS1="$(uname -n) >"

(Note the use of the $() to run commands instead of the `` (backticks). The $() is much easier to read and does the same thing.)
James R. Ferguson
Acclaimed Contributor

Re: Display DNS names as a prompt

Hi:

> In TRU64, export PS1="`uname -n >" solves the problem.

Well, while each Unix has some minor differences, each variation has a common ancestor. Had you provided the closing backtick (after '-n') (and perhaps quickly examined the manpages) *and* then tried your syntax at the commnad line, you would have answered and solved your own problem. Experimentation = learning.

Regards!

...JRF...

Anuraag
Occasional Advisor

Re: Display DNS names as a prompt

Got the solution