And no, don’t try to convince me that I should switch to tmux!
I have been using GNU Screen for ages. It’s a convenient and safe way to manage a remote Linux server. Screen enables me to have multiple ‘windows’ available in a terminal, running its processes independently. When I close screen (or when my ssh connection fails), the processes contained in the remote screen session keep running.
It’s how I can compile Chromium for instance – a package compilation can take up to 12 hours. I go to sleep and the next morning I reconnect the screen client to the remote socket of the still running screen daemon and continue as if I was never away.
Yes I know that tmux is supposed to be the successor of screen, but I simply don’t care.
I operate multiple Slackware servers in remote datacenters and run screen sessions over ssh connections. To avoid any confusion about the server that I am executing commands on, I have configured screen to show relevant information in the bottom line. This concept is called “hardstatus” in screen. Here’s an example showing the three active bash prompts, highlighting that I am currently working in ‘Window 1‘, but it also shows the server’s hostname in green and the local time in blue.
Before typing anything, I first look at the green text to confirm that I am connecting to the right server.
Now, recently Slackware-current upgraded from GNU screen 4 to version 5 and with that, an old compatibility syntax was removed – a syntax that made it easy to define the colors in that status line. But the info page which describes the syntax is probably written for even more stubborn people than me.
It took me a while to get the look and feel of my screen 4.x status line reproduced in screen 5. In fact, I fixed the hardstatus definition only today (after 4 months of barely tolerating the junked colors and finally having enough of it), and I want to share it with you.
This is what defines the status line in my Linux computers with screen 4:
# Tabbed colored hardstatus line: hardstatus alwayslastline hardstatus string '%{= Kd} %{= Kd}%-w%{= Kr}[%{= KW}%n %t%{= Kr}]%{= Kd}%+w %-= %{KG} %H%{KW}|%{KY}%101`%{KW}|%D %M %d %Y%{= Kc} %c%{-}'
And this is how the definition had to change for screen 5 in order to show the exact same status line:
# Tabbed colored hardstatus line: truecolor on hardstatus off hardstatus alwayslastline '%{= .;#999999} %{= .;#999999}%-w%{= #ff0000;#999999}[%{= #ffffff;#999999}%n %t%{= #ff0000;#999999}]%{= .;#999999}%+w %-= %{#00ff00;#999999} %H%{#ffffff;#999999}|%{#ffff00;#999999}%101`%{#ffffff;#999999}|%D %M %d %Y%{= #00ffff;#999999} %c%{-}'
In case you are curious about my full ~/.screenrc
definition file, you can find it in liveslak: https://git.liveslak.org/liveslak/tree/make_slackware_live.sh?h=1.8.1.2#n2053 – I still have to fix the hardstatus definition there though.
I hope that this helps some of you old guys.
In the comments section below, I won’t tolerate GNU haters, screen haters or other evangelists. Keep it civil.
Cheers, Eric
Hello Eric,
I keep running an irssi client in screen in my VPS @ Linode. This way I am permanently connected to some IRC channels even when my desktop at home is off. To visit these channels I just ssh to the VPS, then type something like:
screen -r 30066.pts-0.darkstar (or just an arrow up once or a few times).
I plan to try tmux instead soon, just too busy at the moment 😉
To combine ssh and screen in one command and also avoid the ‘arrow up’:
ssh 192.168.x.x -Xt screen -aAdr -RR irssi irssi
Better yet, the first time you connect to your ssh server with this command it starts irssi in a new screen session. The next time it just reconnects to the now existing session.
I put the above command in a bash script in mij local PATH so that I only have to enter the name of the script (or you could autostart it at login).
I give my screen sessions a name so that it is easier to reconnect to them later.
When starting a new session, I run “screen -S ALIEN” and after disconnecting when I want to connect again I can do “screen -x ALIEN” without having to arrow-up or do a “screen -list”.
By the way, I use “-x” instead of “-r” because that allows me to indiscriminately connect to detached as well as non-detached sessions.
“Us” old guys thank you sir! 😉
No hate from me. Screen’s dead useful. (I’d use it to admin a minecraft server.)
I ended up in the same boat when the screen 5 update unexpectedly broke my status line and in my frustration I ended up getting used to tmux (which is good in its own way), but I still wanted to figure out how to fix my screen config.
It turns out the manual lists indexes you can use for basic colors:
https://www.gnu.org/software/screen/manual/html_node/String-Escapes.html
0 black
1 red
2 green
3 yellow
4 blue
5 magenta
6 cyan
7 white
> The old format of specifying colors by letters (k,r,g,y,b,m,c,w) is now deprecated. Colors are coded as 0-7 for basic ANSI, 0-255 for 256 color mode, or for truecolor, either a hexadecimal code starting with x, or HTML notation as either 3 or 6 hexadecimal digits. Foreground and background are specified by putting a semicolon between them. Ex: #FFF;#000 or i7;0 is white on a black back?ground.
> You can also use the pseudo-color ‘i’ to set just the brightness and leave the color unchanged. As a special case, %{-} restores the attributes and colors that were set before the last change was made (i.e., pops one level of the color-change stack).
This means that unless you are doing something fancy, the change is very minor:
https://github.com/specious/dotfiles/blob/5c7b519/screenrc#L33
My current status line:
caption always “%{= 7;0}%-w%{=b 7;4}%n %t%{-}%+w%-=%{=b}%S :: @%H – %Y-%M-%d %c”
I have a grey background in my status bar, and I found no way to get that back using the new 0-7 color numbering scheme, not even using the color modifiers idubrsB.
My “screen4” hardstatus string is:
'%{= Kd} %{= Kd}%-w%{= Kr}[%{= KW}%n %t%{= Kr}]%{= Kd}%+w %-= %{KG} %H%{KW}|%{KY}%101`%{KW}|%D %M %d %Y%{= Kc} %c%{-}'
If you manage to make it look the same in screen5 without using truecolor I would be very happy 🙂