Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash or python command to cycle through terminals and execute commands on them?

Stating the problem in a simplified form: I'm ssh'ing to two servers using two bash terminals and running programs on the servers whose outputs I need to continuously view. Server1's output appears on terminal1 and Server2's output on terminal2.

Is there a way to run a script which is aware of how many terminals are open, and be able to cycle through them and execute bash commands on them?

Pseudocode:

open terminal1
run program1
open terminal2
run program2
switch to terminal1
run program3 on terminal1

Looked at the man page for xterm, but there was no option to switch between terminals.
The closest I could get was this and this. But both didn't help.

like image 729
Nav Avatar asked Jun 23 '26 00:06

Nav


2 Answers

In [5]: import subprocess

In [6]: import shlex

In [7]: subprocess.Popen(shlex.split('gnome-terminal -x bash -c "ls; read -n1"'))
Out[7]: <subprocess.Popen object at 0x9480a2c>
like image 117
Kracekumar Avatar answered Jun 25 '26 22:06

Kracekumar


screen

like image 28
Ross Patterson Avatar answered Jun 25 '26 21:06

Ross Patterson