LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-30-2005, 03:27 PM   #1
wmqman
LQ Newbie
 
Registered: Aug 2005
Distribution: RedHat 9 for Intel + latest Legacy patches
Posts: 2

Rep: Reputation: 0
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??
 
Old 08-30-2005, 08:37 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,772

Rep: Reputation: 309Reputation: 309Reputation: 309Reputation: 309
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?
 
Old 08-30-2005, 08:57 PM   #3
freakyg
Member
 
Registered: Apr 2005
Distribution: LFS 5.0 and 6.1
Posts: 705

Rep: Reputation: 30
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!!
 
Old 09-01-2005, 01:30 PM   #4
wmqman
LQ Newbie
 
Registered: Aug 2005
Distribution: RedHat 9 for Intel + latest Legacy patches
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
changing the default desktop in login screen Niflheim Linux - Newbie 3 03-27-2005 07:57 AM
Changing default login on Fedora Core 2?? strobart Fedora 8 09-03-2004 06:19 AM
changing my default shell after login? Quartzophobia Linux - General 1 02-11-2004 11:36 AM
default prompt nero64 Linux - Newbie 6 12-10-2002 06:16 PM
Xwindow login prompt problems uglykid General 1 07-20-2001 07:47 AM


All times are GMT -5. The time now is 09:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration