So I have 2 terminals open in front of me;

  1. /dev/pts/1 - 'the controller'
  2. /dev/pts/2 - 'the receiver'

I am currently using ttyecho to execute commands in /pts2 from /pts1.
I can list the screens - ttyecho -n /dev/pts/2 screen -ls fine from /pts1 and see the results in /pts2.
I can attach to a screen ttyecho -n /dev/pts/2 screen -x [blah] from /pts1 on /pts2 fine.. But what I can't do, is when attached to a screen then detach from it.

So if /dev/pts/2 is then inside a screen, I am trying to detach from it by executing a command using ttyecho from /dev/pts1

I've tried sending...

ttyecho -n /dev/pts/2 ^a+d  
ttyecho -n /dev/pts/2 screen -d -r 
ttyecho -n /dev/pts/2 screen -D -RR
ttyecho -n /dev/pts/2 screen -d -r
ttyecho -n /dev/pts/2 screen -DRi
ttyecho -n /dev/pts/2 Ctrl+a+d
ttyecho -n /dev/pts/2 Ctrl+a d
ttyecho -n /dev/pts/2 CTRL + A
ttyecho -n /dev/pts/2 control+a

So I guess what I need is either:

  • A command I can send that will detach the screen OR
  • Someway to send some kind of pseudo keyboard commands via ttyecho to that other screen to detach it.

Any help most appreciated.


You can do

$ screen -ls

This will list all the screen sessions like this.

There are screens on:
        8365.pts-6.vm2    (Attached)
        7317.pts-1.vm2    (Attached)
2 Sockets in /var/run/screen/S-root.

Then you can detach any screen session with the help of screen id.

For eg:

$ screen -d 8365
[8365.pts-6.vm2 detached.]

There’s no need to use ttyecho to detach the screen session, you can ask screen to do it for you:

screen -d pts-2

This will detach the session matching the name “pts-2”, which by default would match a screen session started on pts/2.

  • Genius, easy when you know how. Thanks Stephen
    – ManreeRist
    Feb 9 '18 at 7:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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