bash - 从另一个窗口在一个终端窗口中执行脚本

标签 bash terminal gnu-screen

我正在使用 screen 在终端窗口中创建多个 shell。 如果我在一个 shell 中执行脚本并使用 ctrl+a c 创建一个新 screen ,有什么方法可以在创建 screen 后,当前在第一个 shell 中执行的脚本向新创建的 shell screen 发出命令.

例如,我有一个脚本:

#!/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 文件包含一个包含数据文件的文件夹名称。

现在执行此脚本时,执行脚本 t.sh 然后创建一个新 screen 并继续循环。 现在最后我得到了 4 个 screen 外壳,但是脚本 t.sh 只在第一个外壳中执行了 4 次。 所以,我基本上需要在 4 个 shell 中分别执行脚本 t.sh

(附:我的基本要求是我有一个 132 核的 CPU,并且希望单独执行一个脚本 132 次并跟踪每次执行的输出。)

最佳答案

要直接回答您的问题,您可以使用 at command 从一个 screen 窗口向另一个窗口发出命令。 ,可以通过screen -X调用。

不过,您的情况更简单:与其发出 ctrl+a c 按键,不如调用 screen bash t.sh $line/x$x。从 screen session 中调用 screencreate a new process in the same session默认情况下(除非清除了 $STY 环境变量)。

关于bash - 从另一个窗口在一个终端窗口中执行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30587886/

相关文章:

linux - 在希捷网络存储上安装

gnu-screen - 在 gnu screen session 中使用 less 时箭头键停止工作

bash - 如何使用 awk 解析多行而不产生奇怪的重复

android - 构建 Android 终端模拟器

terminal - iTerm2 键盘快捷键 - 分割 Pane 导航

linux - 在一行中使用 'su' 命令登录

linux - 如何在循环中附加到 screen session ?

linux - GNU 并行组合,多次使用参数列表

Linux Shell 脚本 : How to compare a specific field in a text document with specific text in an if statement

linux - 更改Linux中的符号链接(symbolic link)