Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

My env: openSUSE Linux 11.3, GNU screen 4.00.03 (FAU) 23-Oct-06

share|improve this question
    
I think you mean that you're using PuTTY to ssh into your server, not telnet. –  EEAA Apr 7 '12 at 18:21
1  
Either SSH or telnet is OK. They make no difference when "screen" is concerned in my question. PuTTY supports telnet as well, you know? –  Jimm Chen Apr 8 '12 at 1:01
    
Is there a reason you dont want to use something like screen -S ptwin1 to start it, and screen -xr ptwin1 to reconnect to it? –  Patrick Apr 8 '12 at 4:09
    
Yes. I am an Linux admin for my corp, and I want to write some scripts to wrap it up, so that my co-workers don't even have to remember those -S -x -d -r switches. –  Jimm Chen Apr 8 '12 at 16:23

1 Answer 1

up vote 0 down vote accepted

After struggling with screen several days, I give up. I've found the much better alternative, tmux.

tmux is more powerful, and employ a much clear design.

For example, to rename current session, just execute

tmux rename armcross

To rename a alien session, just do

tmux rename -t oldname newname

--regardless of whether it is detached or attached.

To switch to another session, just execute:

tmux switch-client -t <targetsessionname>

--you don't have to know your current session name to do that, no matter target session is in attached or detached state.

I just demonstrate the command-line usage of tmux; for interactive use, tmux is also much better than

This book is a good tutorial on tmux tmux: Productive Mouse-Free Development

==== A word to lain:

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.