You are not logged in.
I didn't think re-opening my old thread was a good idea so I'm starting new one to address 1 issue I have left to conquer.
With some help from JWR I have built my prompt and it works for users and root logged into a local machine. Logging into a remote machine does change my user's prompt by appending :ssh: to it. However, as the root user logged into a remote machine, which should have the :ssh: appended to it, doesn't work. By that I mean that root logged in to a remote system doesn't get the correct prompt. I want the prompt to look like this for root:
:root: ~ :ssh:Instead I get this prompt which lacks the word "root" in it:
: ~ ::ssh: This is my prompt script so far and I'd really appreciate some help to nail down this glitch.
The script for root and user are identical apart from having a different prompt uncommented.
### Other prompt styles to use later
This is root's current script:
### A PS1 for each computer is on the respective lines in this order:
### ### White Yunzi / Silver Yunzi / Pink Yunzi / Rainbow EeePC
if [[ -n $SSH_CLIENT ]]; then
# PS1='\[\e[0;37m\]: \[\e[1;32m\]\W\[\e[0;37m\] :\[\e[0;37m\]:\[\e[1;33m\]ssh\[\e[m\]\[\e[0;37m\]: ' # WY SSH
PS1='\[\e[0;37m\]: \[\e[1;33m\]\W\[\e[0;37m\] :\[\e[0;37m\]:\[\e[1;33m\]ssh\[\e[m\]\[\e[0;37m\]: ' # SY SSH
# PS1='\[\e[0;37m\]: \[\e[1;35m\]\W\[\e[0;37m\] :\[\e[0;37\m]:\[\e[1;33m\]ssh\[\e[m\]\[\e[0;37m\]: ' # PY SSH
# PS1='\[\e[0;37m\]: \[\e[1;33m\]\W\[\e[0;37m\] :\[\e[0;37m\]:\[\e[1;33m\]ssh\[\e[m\]\[\e[0;37m\]: ' # EeePC SSH
elif [[ ${EUID} == 0 ]]; then ## :root: ~ :
# PS1='\[\e[0;37m\]:\[\e[1;32m\]\u\[\e[0;37m\]:\[\e[0;37m\]: \[\e[1;92m\]\W \[\e[0;37m\]:\[\e[m\] \[\e[0;37m\] ' # WY root
PS1='\[\e[0;37m\]:\[\e[1;34m\]\u\[\e[0;37m\]:\[\e[0;37m\]: \[\e[1;34m\]\W \[\e[0;37m\]:\[\e[m\] \[\e[0;37m\] ' # SY root
# PS1='\[\e[0;37m\]:\[\e[1;35m\]\u\[\e[0;37m\]:\[\e[0;37m\]: \[\e[1;35m\]\W \[\e[0;37m\]:\[\e[m\] \[\e[0;37m\] ' # PY root
# PS1='\[\e[0;37m\]:\[\e[1;33m\]\u\[\e[0;37m\]:\[\e[0;37m\]: \[\e[1;33m\]\W \[\e[0;37m\]:\[\e[m\] \[\e[0;37m\] ' # EeePC root
else ## : ~ :
# PS1='\[\e[0;37m\]: \[\e[1;32m\]\W\[\e[0;37m\] :\[\e[m\]\[\e[0;37m\] ' # WY user
PS1='\[\e[0;37m\]: \[\e[1;34m\]\W\[\e[0;37m\] :\[\e[m\]\[\e[0;37m\] ' # SY user
# PS1='\[\e[0;37m\]: \[\e[1;35m\]\W\[\e[0;37m\] :\[\e[m\]\[\e[0;37\m] ' # PY user
# PS1='\[\e[0;37m\]: \[\e[1;33m\]\W\[\e[0;37m\] :\[\e[m\]\[\e[0;37m\] ' # EeePC user
fi
## :root: ~ :ssh:
#PS1='\[\e[0;37m\]:\[\e[1;34m\]\u\[\e[0;37m\]:\[\e[1;34m\] \W \[\e[0;37m\]:\[\e[m\]\[\e[0;37m\]\[\e[1;33m\]ssh\[\e[0;37m\]: ' # SY root
## :root:: ~ :ssh:
#PS1='\[\e[0;37m\]:\[\e[1;34m\]\u\[\e[0;37m\]:\[\e[0;37m\]: \[\e[1;34m\]\W \[\e[0;37m\]:\[\e[m\]\[\e[0;37m\]\[\e[1;33m\]ssh\[\e[0;37m\]: ' # SY root
## :root:: ~ ::ssh:
# PS1='\[\e[0;37m\]:\[\e[1;34m\]\u\[\e[0;37m\]:\[\e[0;37m\]: \[\e[1;34m\]\W\[\e[0;37m\] :\[\e[m\]:\[\e[m\]\[\e[0;37m\]\[\e[1;33m\]ssh\[\e[0;37m\]: ' # SY rootLast edited by MoonSwan (2014-11-19 09:23:02)
Offline
So it works for root locally, just not when you SSH in as root or change to root in an SSH session?
Also, it might help if you remove the commented lines, it is pretty hard to work out what is going on in there...
Offline
So it works for root locally, just not when you SSH in as root or change to root in an SSH session?
Yes, you're quite correct.
Also, it might help if you remove the commented lines, it is pretty hard to work out what is going on in there...
I agree and I found a bunch of \'s that I missed. Sorry about that!
Here's the config stripped of extraneous junk:
if [[ -n $SSH_CLIENT ]]; then
PS1='\[\e[0;37m\]: \[\e[1;32m\]\W\[\e[0;37m\] :\[\e[0;37m\]:\[\e[1;33m\]ssh\[\e[m\]\[\e[0;37m\]: ' # WY SSH
elif [[ ${EUID} == 0 ]]; then ## :root: ~ :
PS1='\[\e[0;37m\]:\[\e[1;32m\]\u\[\e[0;37m\]:\[\e[0;37m\]: \[\e[1;92m\]\W \[\e[0;37m\]:\[\e[m\] \[\e[0;37m\] ' # WY root
else
PS1='\[\e[0;37m\]: \[\e[1;32m\]\W\[\e[0;37m\] :\[\e[m\]\[\e[0;37m\] ' # WY user
fiEdit: stripped out two comments I'd missed earlier.
Last edited by MoonSwan (2014-11-19 08:27:27)
Offline
Well, the test looks for an SSH connection, which is satisfied, therefore your prompt is set to WY SSH: as expected.
You would need more complex logic to include a test for both SSH and root. But then, as you won't be SSH'ing in as root, that shouldn't be necessary... ![]()
Offline
Thou art evil! Hm but if I login as a user then "su" to the root account and want that prompt appended with SSH I would need much more complex code too, I presume?
Offline
Yes. It isn't much more complex, just another level of test:
if [[ -n $SSH_CLIENT && $EUID = 0 ]]; thenOffline
Oh good lord your code is something I used a few days ago and it worked. I was wondering why my stanza wasn't working anymore! OK I feel silly now and I am in your debt for pointing that out.
Thank you and I wish I had a way to re-pay your kindness. I'll mark this as solved.
Edit: I am not sure where to put your code. Does it just go at the top above the other SSH test statement?
Edit 2: Nevermind I figured it out. I really have to stop coding and poking my laptop at 2 a.m.
Last edited by MoonSwan (2014-11-19 08:56:22)
Offline
OK I used the stripped source config file and my normal config but with your new code I'm still not getting an SSH at the prompt. Root still doesn't show up with the word "root" in the prompt either.
What am I doing wrong? Oh I did get the hint about logging in as root. For now, though, I just want this script to work because I want to see where my error, or lack of correct code, is in the script.
Edit: OK I'm obviously too tired to do this. I figured out my coding error is that I never put the \u\ flag in the prompt so I won't see "root" no matter what I do.
Last edited by MoonSwan (2014-11-19 09:22:17)
Offline