Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I often have to open multiple ssh sell terminals of remote servers together., eg. Dev and test. These paths and applications are exactly similar. And I am often confused if I run a particular command intended on one window to the other one.

For example, I want to update svn of a dev environment, but likely to run it on test environment, which if done, invites problems.

Would you please share how you handle controlling the terminals precisely?

share|improve this question

2 Answers 2

I use different background colors for different environments:
production: red - think before you hit enter
testing: yellow - sure you want to do that?
dev: green - feel free to go crazy

Another must-have are different prompts, a good idea would be to include the hostname.

share|improve this answer
2  
Different prompts with hostnames should be the starting point... –  jasonwryan Aug 25 at 20:43

Rather obviously, in the end it's always you who have to know what commands you are putting into which terminal. Now, you can do several things to distinguish the sessions:

  • use different colours of the terminals (this includes background colours). One way to achieve this is to make the terminal use a specific background however, it is more flexible to request this in the shell - most likely in the command prompt string (which you put into your shell initialisation file (see below);

  • use different command prompts. This is usually achieved by setting an environment variable, e.g. PS1 - read your shell documentation on what exactly needs to be done. Use ANSI escape sequences to introduce colour and/or positioning (note that especially the latter may break output in some terminals).

    An example for bash could look like this:

    export PS1="^[[31;1m\u@\h:^[[0;1m\w^[[0m "
    

    here \u stands for username, \h for hostname, \w for current working directory, so this will give you a prompt like this one:

    example prompt

    The ^[ stands for the Escape character, which you usually insert by pressing Ctrl+V and then Esc. It is not two characters ^ and [ - so you can't copy it verbatim from here and expect it to work.

    There are endless ways to tweak this - for the purpose of drawing one's attention to a particularly dangerous terminal without straining the eyes too much, using e.g. bright red colour for the commands as well might be a reasonable option (you'd need to use ^[[0;31;1m instead of just ^[[0m at the end of the prompt string).

  • Some terminals can interpret some escape sequences as a title - that way you can put the contents of the prompt into the window title. Be aware that this will interfere with shell's ability to properly break command lines unless you tell it to ignore those escape sequences (this is of course also valid for colours - in bash this is done by enclosing the "zero-width" parts between \[ and \]).

  • Use terminal multiplexer on the remote machines (using it locally is not a bad idea either). This cannot be overrated, especially for remote work it can save one a lot of hassle during connection drops. AFAIK, it is possible to get a custom status line in screen, but people try tmux usually find it better in every conceivable way.

  • some shells allow you to hook your own functionality into the command processing, thus you can make the shell ask you whether you are really sure about executing a specific command, before disaster happens.

Combine the above.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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