How to show hostname infor after login


 
Thread Tools Search this Thread
Operating Systems AIX How to show hostname infor after login
# 8  
Old 04-01-2009
Not working for me

Quote:
Originally Posted by Ikon
Not sure on AIX but on linux you can do:

Code:
PS1="\H/#"

Where:
Code:
...
       \h     the hostname up to the first `.'
       \H     the hostname
...
       \w     the current working directory
...

I entered the following, expecting to get "hostname:/current/path> " as a prompt (based on your post), but look what happened:

Code:
/msa1/agility/devel/bin> PS1="\h:\w> "
h:w> uname -s
Linux
h:w>

Did I misunderstand something?
~Marcus
# 9  
Old 04-01-2009
for AIX, put the sytax as below into your .profile

# Set prompt to display login@hostname:current directory

PS1='$'LOGIN"@"`uname -n`":"'$'PWD" # "; export PS1


Or for all users, put sytax into /etc/profile as below. It will let all users prompt host name and current directory.

# Set the primary prefix prompt to display machine name and current directory
if [ "`id | grep '^uid=0('`" != "" ]
then
PS1="[`uname -n`:"'$'PWD"] # "; export PS1
else
PS1="[`uname -n`:"'$'PWD"] $ "; export PS1
fi
# 10  
Old 04-01-2009
Yes, I'm familiar with doing it that way. I was intrigued by the control character construct (e.g., \h \w etc.) and wanted to see that work. That is what I was having trouble with.

I did it on the command line. Is there some special processing that happens in .profile? In other words, if I put the same statement (PS1="\h:\w> ") in my .profile, does it process the special control characters? (I cannot imagine that is the case.)
# 11  
Old 04-01-2009
Are you using csh? ksh and bash both seem to "see" the changes to PS1 immediately. (i.e. without having to export them). What shell are you using?
# 12  
Old 04-01-2009
Quote:
Originally Posted by wempy
Are you using csh? ksh and bash both seem to "see" the changes to PS1 immediately. (i.e. without having to export them). What shell are you using?
ksh.
This works fine on the command line:
Code:
$ D='$PWD'
$ PS1="$(hostname -s):$D> "
strawboss:/home/mlibby> cd /msa1/profiles/mlibby/ksh
strawboss:/msa1/profiles/mlibby/ksh>

The problem I'm having is when I'm trying to see the control characters work. According to an earlier post, I should be able to use "\h" for short host name--in lieu of $(hostname -s); I should be able to use "\w" for working directory--in lieu of D='$PWD' and $D.

I know how to get the prompt I want. The control character (back-slash construct) was new information to me, and I was trying to get that to work. That is what I'm having difficulty with. According to the earlier post in this thread (if I read it right), I should be able to type this to get the same results as above:
Code:
$ PS1="\h:\w> "
h:w>

... but as you see, instead I get the prompt "h:w>"
~Marcus
# 13  
Old 04-01-2009
ah, I see what you mean. As I only have a Linux machine here, I can't say for "real" ksh but pdksh does not understand \u@\h: \w escapes for the PS1 variable. They appear to only apply to bash.

Having just looked it up, the escape sequences only applie to bourne type shells not to korn or csh. To have dynamic, colourful prompts with those shells you are going to have to be more creative. (chapter 4 of "Unix Power Tools" has a very good section on prompts).
UNIX Power Tools - Google Book Search

Last edited by wempy; 04-01-2009 at 05:13 PM.. Reason: added more information
# 14  
Old 04-01-2009
Thanks wempy. I missed the part about it only working with bourne/bourne-again in the initial post. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Cannot show graphical login display

Hi all, I'm running Red Hat Enterprise Linux Server 6.3 Santiago. I already installed the X Window package during installation and the graphical login display can be shown normally after installation. Yesterday, I accessed remotely by GUI mode using VNC viewer and somehow it got crashed.... (1 Reply)
Discussion started by: sergionicosta
1 Replies

2. UNIX for Advanced & Expert Users

Hostname -f hostname: Unknown host

deleted (0 Replies)
Discussion started by: hce
0 Replies

3. Emergency UNIX and Linux Support

HP UX - ILO Console hostname different than Machine Hostname...

Hi All, So we added a new HP-UX 11.31 machine. Copied OS via Ignite-UX (DVD)over from this machine called machine_a. It was supposed to be named machine_c. And it is when you log in...however when I'm in the ILO console before logging in, it says: It should say: What gives? And how do... (4 Replies)
Discussion started by: zixzix01
4 Replies

4. Shell Programming and Scripting

Show the login of users connected with awk

Hello everyone, I was trying to get the all logins of the users connected with awk, using "w" command, I probe with this: w|awk 'NR>2 {print $1}' But I'm not sure... is it ok? Thank You so much! (2 Replies)
Discussion started by: adiegorpc
2 Replies

5. Solaris

error message rmclomv ... SC Login Failure for user Please login:

Hello World ~ HW : SUN Fire V240 OS : Solaris 8 Error message prompts 'rmclomv ... SC login failure ...' on terminal. and Error Message prompts continually 'SC Login Failure for user Please login:' on Single Mode(init S) The System is in normal operation, though In case of rain, Can... (1 Reply)
Discussion started by: lifegeek
1 Replies

6. Solaris

How grep only the capacity infor from df -k using sun solaris

Hello experts, when i get an output for df -k; i get the below output Filesystem kbytes used avail capacity Mounted on /dev/vd/vdisk3 8241689 1973089 6186184 25% / /proc 0 0 0 0% /proc mnttab 0 ... (3 Replies)
Discussion started by: streddy
3 Replies

7. Cybersecurity

APACHE: Tie in Web Page login with server login

Hello, I have created a web page on a server using apache and added .htaccess and .htpasswd in the folder for authentification. I was wondering if there was anyway to tie-in the login for this page with the login used to logon to the server. i.e. the same login info. is used for both, when... (1 Reply)
Discussion started by: WhotheWhat
1 Replies

8. Web Development

APACHE: Tie in Web Page login with server login

Hello, I have created a web page on a server using apache and added .htaccess and .htpasswd in the folder for authentification. I was wondering if there was anyway to tie-in the login for this page with the login used to logon to the server. i.e. the same login info. is used for both,... (2 Replies)
Discussion started by: WhotheWhat
2 Replies

9. AIX

How to disable user login infor?

If user login and don't do anything in 15 mins, the user is kicked off from the server. how to disable it? (5 Replies)
Discussion started by: rainbow_bean
5 Replies

10. UNIX for Dummies Questions & Answers

Solaris - unknown hostname - how can I change hostname?

Hello, I am new to Solaris. I am using stand alone Solaris 10.0 for test/study purpose and connecting to internet via an ADSL modem which has DHCP server. My Solaris is working on VMWare within winXP. My WinXP and Solaris connects to internet by the same ADSL modem via its DHCP at the same... (1 Reply)
Discussion started by: XNOR
1 Replies
Login or Register to Ask a Question