Detach current session and attach to another session, done with one script, can I?
Posted
by
Jimm Chen
on Server Fault
See other posts from Server Fault
or by Jimm Chen
Published on 2012-04-07T16:04:32Z
Indexed on
2012/04/07
17:34 UTC
Read the original article
Hit count: 499
gnu-screen
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:
$ screen -ls
There are screens on:
22041.pts-9.linux-ic37 (Attached)
21385.pts-4.linux-ic37 (Attached)
2 Sockets in /var/run/uscreens/S-chj2.
?STEP 2?
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.
Waiting for your kind answer. Thank you.
My previous questions regarding GNU screen:
- GNU screen, how to get current sessionname programmatically
- Is it possible to change GNU screen session name after created?
- How do I know I'm running inside a linux "screen" or not?
My env: openSUSE Linux 11.3, GNU screen 4.00.03 (FAU) 23-Oct-06
© Server Fault or respective owner