After reading the vague official doc of GNU screen( http://www.gnu.org/software/screen/manual/screen.html ) and asking quite some questions at this site. I still cannot figure out how to accomplish such a task with a shell script. This task costs some words to describe.

Assume I'm using PuTTY to telnet into my Linux server.

【STEP 1】 Launch 2 telnet connections .

From putty window 1 (PTWIN1)，telnet into Linux Bash shell, execute screen -RR to launch a screen session, and get session name 21385.pts-4.linux-ic37 .

From putty window 2 (PTWIN2), do that same as in PTWIN1, but this time, I get session name 22041.pts-9.linux-ic37 .

Now, we have two screen sessions running simultaneously. We can check this:

Assume that for some reason, PTWIN1's TCP connection is lost abnormally(but server doesn't know that), and an urgent work is pending on session 21385 and I want to quickly regain control of it. Fortunately, we know the 21385 session is still there, so, I want to have PTWIN2 attach to session 21385. Because I hate to remember the esoteric screen option all the time, so I decide to write a script called sttach.

I hope that

sttach 21385.pts-4.linux-ic37

can let me attach to session 21385(for PTWIN2).

Now, let's say sttach works well and I take control of 21385 on PTWIN2.

【STEP 3】

Some minutes later. I want to go back to work on session 22041. Here, please allow me to have PTWIN2 remain associated with session 21385. What I would like to do is to launch another putty window (PTWIN3), telnet into server, and execute

sttach 22041.pts-9.linux-ic37

in hope that I can resume session 22041 on PTWIN3 .

You can see the benefit of sttach: as long as I know the target session name, I can call it to have my PuTTY window switch to that session, regardless whether the target session is "(Attached)" or "(Detached)", and regardless whether the running context is inside a screen session or not.

Now the question: How to write the (Bash) script sttach? I mean, run screen with appropriate options in sttach to accomplish the goal.

PLEASE DO NOT delete my post just because I turn to tmux. This is definitely an ANSWER. It is just like some question is about ten-year-old Linux 2.2 but someone suggest it can be resolved easily using Linux 2.6; NOT like someone saying Windows can do something better than Linux.