bash - 在 nohup bash 脚本中运行多个 matlab 实例

标签 bash matlab terminal nohup

我正在尝试执行以下操作。 现在,我通过 ssh 连接到远程机器并使用 nohup 命令运行我的分析

nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 &

现在我想编写一个脚本,在后台运行几个 nohup 命令一个接一个。 我设法做到了

#!/bin/bash
matlab -nodesktop -nodisplay -r "mycode;quit;" > output.txt

但不仅代码只能在一个 CPU 上工作,而且它会进入无限循环,永远不会完成工作。

我能解决吗? 重要的是我可以在启动 script.sh 后关闭终端

编辑: 多亏了你,我设法做到并让以下事情顺利进行

ssh user@ipaddress
screen
cd folder1/
nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 &
exit
screen
cd folder2/
nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 &
exit

现在可以编写一个脚本吗?因为我注意到每次输入 screen 后我都必须立即按 Enter。

编辑2:@Peter 我按照你的建议做了

#!/bin/bash
cd folder1/
matlab -nodesktop -nodisplay -r "mycode;quit;" < /dev/null  > output.txt
cd folder2/
matlab -nodesktop -nodisplay -r "mycode;quit;" < /dev/null  > output.txt

可是只跑第一个matlab,怎么可能?

最佳答案

汇总所有您可以尝试的建议和想法:

#!/bin/bash
ssh user@ipaddress "
cd folder1/
nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 &
cd folder2/
nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 &
"

或者

#!/bin/bash
ssh user@ipaddress "
cd folder1/
nohup matlab -nodesktop -nodisplay -r 'mycode;quit;' < /dev/null  > output.txt 2>&1 &
cd folder2/
nohup matlab -nodesktop -nodisplay -r 'mycode;quit;' < /dev/null  > output.txt 2>&1 &
"

或者

#!/bin/bash
ssh user@ipaddress "
cd folder1/
screen -dm matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1
cd folder2/
screen -dm matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1
"

或者

#!/bin/bash
ssh user@ipaddress "
cd folder1/
screen -dm matlab -nodesktop -nodisplay -r 'mycode;quit;' < /dev/null  > output.txt 2>&1
cd folder2/
screen -dm matlab -nodesktop -nodisplay -r 'mycode;quit;' < /dev/null  > output.txt 2>&1
"

您也可以尝试 expect 来控制 matlab 而不是发送 mycode.m 或使用 -r 给它。

也尝试在 screen 上执行 nohup。而且我认为您不再需要向其中添加 &,因为 screen 默认情况下已经作为守护进程运行。

关于bash - 在 nohup bash 脚本中运行多个 matlab 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18510304/

相关文章:

javascript - 我怎样才能在Javascript中实现这样的多维数组?

bash - 带有 comm 命令的行号。是否可以?

matlab - matlab中的矩阵矩阵

bash - 如何重复启动和终止一个永无止境的 bash 进程

matlab - 如何高效绘制多边形多孔?

linux - 如何在不调用其路径的情况下执行 bash 脚本?

unix - Unix 中打印回车的默认行为是什么?

terminal - 对于在 centos 7 中找不到的 root 访问 Composer

linux - 如何获取bash脚本中小于号(<)后面的参数?

java - 在嵌入式 linux 上启动后自动在后台启动 java 应用程序