Problems changing the default login prompt...
Hello all,
I've administated RedHat for some years now both at home and at various jobs, but I've never had to change the default login prompt for all users before strangely enough. The default /etc/bashrc for RedHat 9 is: # /etc/bashrc # System wide functions and aliases # Environment stuff goes in /etc/profile # by default, we want this to get set. # Even for non-interactive, non-login shells. if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then umask 002 else umask 022 fi # are we an interactive shell? if [ "$PS1" ]; then if [ -x /usr/bin/tput ]; then if [ "x`tput kbs`" != "x" ]; then # We can't do this with "dumb" terminal stty erase `tput kbs` elif [ -x /usr/bin/wc ]; then if [ "`tput kbs|wc -c `" -gt 0 ]; then # We can't do this with "dumb" terminal stty erase `tput kbs` fi fi fi case $TERM in xterm*) if [ -e /etc/sysconfig/bash-prompt-xterm ]; then PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm else PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"' fi ;; screen) if [ -e /etc/sysconfig/bash-prompt-screen ]; then PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen else PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"' fi ;; *) [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default ;; esac # Turn on checkwinsize shopt -s checkwinsize [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ " if [ "x$SHLVL" != "x1" ]; then # We're not a login shell for i in /etc/profile.d/*.sh; do if [ -r "$i" ]; then . $i fi done fi fi # vim:ts=4:sw=4 I changed it to this: # /etc/bashrc # System wide functions and aliases # Environment stuff goes in /etc/profile # by default, we want this to get set. # Even for non-interactive, non-login shells. if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then umask 002 else umask 022 fi # are we an interactive shell? if [ "$PS1" ]; then stty erase ^? case $TERM in xterm*) PROMPT_COMMAND="`tput bold`"'$LOGNAME@'"$HOSTNAME:"'${PWD#$HOME/}'"`tput rmso` > " ;; screen) PROMPT_COMMAND="`tput bold`"'$LOGNAME@'"$HOSTNAME:"'${PWD#$HOME/}'"`tput rmso` > " ;; *) PROMPT_COMMAND="`tput bold`"'$LOGNAME@'"$HOSTNAME:"'${PWD#$HOME/}'"`tput rmso` > " ;; esac # Turn on checkwinsize shopt -s checkwinsize # [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ " if [ "x$SHLVL" != "x1" ]; then # We're not a login shell for i in /etc/profile.d/*.sh do if [ -r "$i" ]; then . $i fi done fi fi # vim:ts=4:sw=4 The default login prompt for all user is now supposed to look something like this: mqm@:/users/service/mqm > But all I get is an error when I log in at root and I returned to the old login prompt. What did I do wrong?? |
I don't know if this will help, but I'll try.
I put this in my /etc/bashrc (and in my user's .bashrc): # bash-specific settings ROOT_UID=0 if [ "$UID" -eq "$ROOT_UID" ] then PS1="\[\033[31;1m\]\u \d] \\$\w\n \[\033[0m\]" else PS1="\[\033[34;1m\]\u \d] \\$\w\n \[\033[0m\]" fi If you study this, or try it out, you wll see that, if the user is root, the prompt is RED (for warning, you can do great damage if you're not careful), and if the user us username, the prompt is blue (cool, can't damage anything other than my user files). So, to correct your problem, perhaps you need something similar to watch for the ROOT_UID, which states what to do if the user is root? |
http://www-128.ibm.com/developerwork...mpt/index.html
check this out also to colorize your prompt.......... save the page local so you can use it as a reference!! |
THANK YOU,
Your comments did the trick. Below are the relevant parts of my new bashrc. I suppose I could have written it more elegantly, but it work just the same. Thanks again... if [ "$PS1" ] then ROOT_UID=0 if [ "$UID" -eq "$ROOT_UID" ] then case $TERM in xterm*) set -o vi stty erase ^? PS1="\[\033[31;1m\]\u@\H:\w > \[\033[0m\]" ;; screen) set -o vi stty erase ^? PS1="\[\033[31;1m\]\u@\H:\w > \[\033[0m\]" ;; *) set -o vi stty erase ^? PS1="\[\033[31;1m\]\u@\H:\w > \[\033[0m\]" ;; esac else case $TERM in xterm*) set -o vi stty erase ^? PS1="\[\033[34;1m\]\u@\H:\w > \[\033[0m\]" ;; screen) set -o vi stty erase ^? PS1="\[\033[34;1m\]\u@\H:\w > \[\033[0m\]" ;; *) set -o vi stty erase ^? PS1="\[\033[34;1m\]\u@\H:\w > \[\033[0m\]" ;; esac fi # Turn on checkwinsize shopt -s checkwinsize if [ "x$SHLVL" != "x1" ]; then # We're not a login shell for i in /etc/profile.d/*.sh do if [ -r "$i" ]; then . $i fi done fi fi |
All times are GMT -5. The time now is 05:25 PM. |