How to make the GNU screen automatically launch upon login?

I have several linux servers to work every day, and I have a GNU screen session for each of them to keep things going.

The question is that I am so tired of the question screen -Rd workevery time I log in, is there a way to get rid of this? Or any workarounds?


Reading @Sami's answer, I did some search in the shell variable $STYand found this:

STY: alternate socket name. If the screen is called and the STY environment variable is set, it only creates a window in a session of a work session, and does not start a new session.

So, I think the key is a variable $STY, we can add it to .bashrc or .profile if it is executed after login. Thanks @Sami

+4
source share
2 answers

It depends on your shell. If you use any derivatives of Bourne Shell (namely Bash) or Bourne Shell itself, put the appropriate commands in ~/.profile:

[ -z "$STY" ] && screen -Rd "work"

This will start a screen session only if you are not already running in a screen session (the screen sets the STY environment variable).

If you are not using Bash or are compatible, use the appropriate shell initialization file with a similar test.

+7
source

You can put an alias in your login script:

alias s="screen -Rd work"

s
+1

All Articles