One of the my main difficulties when I am administrating remote servers, its to identify the server that I'm working, once the shell is very similar between them (in fact, only the user is different in most cases).

I would like to know of is possible to create custom shells considering the remove server which I am connected.

Thanks for the help, Best regards!

link|improve this question

22% accept rate
feedback

4 Answers

If you mean custom shell prompt, take a look at the PS1 variable (man bash, search for PS1). It has lots of options. Here is a full guide, but for a start try

export PS1=\u@\H \$>

which gives you a prompt like

username@full.host.name $> _
link|improve this answer
Instead of just the prompt, I would like to customize the entire shell window (different background, watermarks, etc.) according the remote server. – Rui Gonçalves Nov 24 '10 at 15:18
@Rui Gonçalves, well in that case you should definitively look into "screen" which is highly customizable in both look and functionalities. – MrShunz Nov 24 '10 at 15:21
1  
byobu is pretty good too, and comes with ubuntu as standard, has colour highlighting, and gives a bar at the bottom of the screen showing hostname. – Sirex Nov 24 '10 at 15:30
And can it be automatically configure according the remote server? – Rui Gonçalves Nov 24 '10 at 15:32
1  
@Rui Gonçalves by default byobu (which is a set of customizations for screen) gives lots of information. If you need more to differentiate servers (like colors and such) you have to tweak the config per-server yourself. – MrShunz Nov 24 '10 at 16:32
feedback

Are you leveraging the PS1 variable for customization? Not all versions of all shells handle the variable in the same manner, but most will accept a \h for hostname, \u for username, and \w for the current working directory.

Please see this page for additional options, examples, and suggestions.

link|improve this answer
feedback

Just use a unique and self-explanatory names for the hostname of your remote servers. Then, you will be able to know on which server you are working!

You can change the hostname from /etc/hostname. Restart the service /etc/init.d/hostname restart. Also, don't forget to update the /etc/hosts file.

link|improve this answer
feedback

regarding ps1 tweaks, this is what i use in my .bashrc

userName=`whoami`
if [ $userName == "root" ]
then
    PS1='\[\e[0;31m\]\u\[\e[0m\]@\[\e[0;35m\]\h\[\e[0m\][$?]\[\e[0;31m\][\W]\[\e[0m\]\[\e[0;31m\]\$\[\e[0m\]: '
else
    PS1='\[\e[0;32m\]\u\[\e[0m\]@\[\e[0;35m\]\h\[\e[0m\][$?]\[\e[0;31m\][\W]\[\e[0m\]\[\e[0;32m\]\$\[\e[0m\]: '
fi

It'll give the username as red when root, green otherwise. and has the hostname and return code of last command. - might help you.

Also, try byobu (as suggested in comment to mrshunz)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.