Executing a script in one end window (s) from another window
I am using screen
to create multiple shells inside a terminal window. If I run the script in one shell and create a new screen with ctrl+a c
, is there any way that after the screen is created, the script is currently executing in the first shell, issue a command to the newly created shell screen.
For example, I have a script as:
#!/bin/bash
while read line
do
echo $line;
for x in {a..d}
do
bash t.sh $line/x$x
xdotool key ctrl+a c
done
done < files
files
the file contains the name of the folder containing the data files.
Now when you execute your script, execute the script t.sh
and then create a new screen and continue the loop. Now at the end I end up with 4 screen shells, but the script t.sh
got 4 times in only the first shell. So, I need to basically execute the script t.sh
in 4 shells individually.
(PS: My basic requirement is that I have a 132 core processor and want to execute the script 132 times individually and track the output of each execution.)
Any help would be appreciated.
Thank!!
source to share
To answer your question directly, you can issue commands from one window to screen
another using a command at
that can be invoked via screen -X
.
Your case is simpler: Instead of triggering a push ctrl+a c
, just call screen bash t.sh $line/x$x
. Calling screen
from a session screen
will create a new process in the same session by default (unless the environment variable $STY
is cleared).
source to share
Are you sure you want to execute the script from another terminal? If you just want to do this for easier monitoring, you can do this:
# my other terminal where I want to see the output:
$ tty
/dev/pts/xx #<~~~~ note this tty device number
# my main terminal:
$ bash t.sh $line/x$x </dev/pts/xx >/dev/pts/xx 2>&1
source to share