Run command in multiple active shells simultaneously

No need for any tools. tmux can handle this:

just open up the panes, ssh to the individual servers, and then Ctrl-B followed by

:setw synchronize-panes 

and all input gets synchronized to all visible panes.
Re-type this or add "off" to the command to leave.


Yes it is possible, with a tool named ttyecho that can emulate user interaction in different terminals.

Download and install:

wget http://www.resulinux.tk/utils/ttyecho.c -O ttyecho.c
gcc ttyecho.c -o /usr/bin/ttyecho

Now lets execute something in other terminal, for example as user john that is loggeg at pts/17 using xterm as you see in the ps command:

ps aux | grep john 
john   9198  0.0  0.0  23836  4524 pts/17   Ss   Jul21   0:00 /bin/bash

Now, lets try to open vi and type some text in the other terminal.

ttyecho -n /dev/pts/17 vi (executed vi command on the other terminal) 
ttyecho  /dev/pts/17 i (entered in insertion mode)
ttyecho -n /dev/pts/17 some text  

When you look to the terminal that john is logged in, you will see that vi is really executed, and you can see the text we type at it "some text". So now you have full control to the others terminal sessions.

Running commands in multiple ssh sessions

Determine the ssh pts devices:

ps aux | grep ssh

root      3540  0.0  0.0  44924  5764 pts/1    S+   14:46   0:00 ssh [email protected]
root      5907  0.0  0.0  44924  5684 pts/17   S+   12:51   0:00 ssh [email protected]
root      8074  0.0  0.0  51216  3948 pts/6    S+   Jul26   0:01 ssh [email protected]

So to execute commands on ssh logged in 192.168.2.77, i just need:

ttyecho -n /dev/pts/6 ls

And the ls command will execute really remotely in the single script!

Tags:

Shell

Tmux