Question

I have several linux servers to work on every day, and I have a GNU screen session on each of them to preserve work progress.

The question is I am so tired of issue screen -Rd work every time I login, is there anyways to get rid of that? Or any workarounds?


Reading @Sami's answer, I did some search on the $STY shell variable and found this:

STY: Alternate socket name. If screen is invoked, and the environment variable STY is set, then it creates only a window in the running screen session rather than starting a new session.

So I think the key is the $STY variable, we may append it to either .bashrc or .profile, as long as it gets executed upon login. Thanks @Sami

Was it helpful?

Solution

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

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

This will only start a screen session in case you're not already running inside a screen session (screen sets environment variable STY).

In case you're not using Bash or compatible, use the proper shell initialization file with a similar test.

OTHER TIPS

You could put an alias in your login script:

alias s="screen -Rd work"

then you'd only have to type

s
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top