N
N
Nikita Bykov2012-01-21 20:08:10
SSH
Nikita Bykov, 2012-01-21 20:08:10

Different console background for different servers?

Good day, Habr!
I think each of those who use the built-in ssh console client from under Linux at least once got confused and executed a command on the server that should have been on the local machine or vice versa, or even confused the server. In general, you understand what I mean;)
Any ideas how to recolor the background of the console so that it is acceptable for server A it was black, server B is gray, etc.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
G
Gribozavr, 2012-01-21
@gribozavr

Make different prompts on different servers, then this setting will be independent of the terminal emulator used. For example, [19:13:13; [email protected]; dir]$you can highlight [email protected] in different colors.

E
Eddy_Em, 2012-01-22
@Eddy_Em

In my opinion, it is enough to enter the server name in PS1:

\[\033[1;33;41m\h>\]\[\033[1;32;40m \D{%d.%m, %H:%M}\] \[\033[1;33;40m\w\]\[\033[1;32;40m\]\[\033[0;37;40m\n

And the color can also be changed using the PS1.
It is convenient to select the desired colors using the script:
#!/bin/sh
# Создан 17-го Июль 2009 года в 10:43
#
echo "
********* СВОЙСТВА **********
Название стиля 		| Код
------------------------|----
Сбросить все свойства 	| 0
Повышенная яркость 	| 1
Пониженная яркость 	| 2
Подчеркнутый		| 4
Нормальная яркость 	| 5
Инвертированный 	| 7
Скрытый 		| 8
********** ЦВЕТА ***********
Название цвета 	|Текст	|Фон
----------------|-------|---
Черный		| 30	| 40
Красный 	| 31	| 41
Зеленый 	| 32	| 42
Желтый		| 33 	| 43
Синий		| 34 	| 44
Маджента 	| 35	| 45
Циановый 	| 36	| 46
Белый		| 37 	| 47
----------------------------
Цвета задаются в формате [свойство;цвет_текста;цвет_фона] (можно указывать только один пар.),
например: \033[37;40m - белый текст на черном фоне
"
HEADER="\t\t"
for B in `seq 40 47`
do
  HEADER=`echo -e "$HEADER Фон $B\t\c"`
done

for A in 1 2 4 5 7 8
  do
  echo -e "\033[0m\n\n Свойство $A:\n$HEADER\c"
  for B in `seq 30 37`
    do
    echo -e "\n Текст $B\t\c"
    for C in `seq 40 47`
      do
        echo -e "\033[$A;$B;$C""m Буквы\t\c"
      done
    echo -e "\033[0m\c"
    done
  done
echo -e "\033[0m\n\n"

V
Vlad Frolov, 2012-01-21
@frol

5 servers in tabs and get the dream of an epileptic. :)
I use "[lapatopa frol:~]$" coloring for the welcome font color, usually green + machine name highlighted in red/yellow (in this case, lapatopa is my local laptop, so I have it green). On production servers, I have the server name highlighted in red :)

A
Alexey Demin, 2012-01-21
@alexd73

I don't have many servers. I work out by setting up Profiles in the Gnome Terminal.
The command for each profile is ssh [email protected]
On the Colors tab, you can customize the look you want.

A
Alexander Karabanov, 2012-01-21
@karabanov

Maybe it will help:

$ setterm -foreground green -background black -store

If it works, then add it to .bashrc (well, or which shell you use) and that's it.
PS
There is a doubt that it will not work (for example, run top , and it will take yes and change all the colors back), but I can’t check: there’s nothing.

C
charon, 2012-01-22
@charon

besides displaying the server name in the prompt, I also highlight different tabs for different machines: 3-local, 4-production-server

R
romik, 2012-01-24
@romik

I once used this:
ssh () { echo -ne '\033]50;colorscheme=BlackOnWhite\a'; =ssh $*; _exitcode=$?; echo -ne '\033]50;colorscheme=Linux\a'; return $_exitcode }
Sharpened for konsole / yakuake, allows you to distinguish the local machine from ssh.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question