循环一系列ssh-ed命令时出现的问题

JMzance

我有一系列要在其上运行相同命令的服务器。每个命令要花费几个小时,并且(即使我使用nohup运行命令并将它们设置为在后台运行),我也必须等待每个命令完成,然后再开始下一个命令。我大致是这样设置的:

在主机上:

for i in {1..9}; do ssh RemoteMachine${i} ./RunJobs.sh; done

每台远程计算机上的RunJobs.sh是:

 source ~/.bash_profile
cd AriadneMatching
for file in FileDirectory/Input_*;
do
    nohup ./Executable ${file} &
done
exit

有谁知道让我不必等下一项工作就可以开始下一项工作的方式吗?或替代地,做这件事的一种更好的方法,我觉得我做的是次优的。干杯,杰克

克里斯蒂安·丘皮图

本地机器的解决方案

基于parallel-ssh

# pssh -P --par 2 --hosts RemoteMachines /opt/RunJobs.sh

或者:

# pssh -i --par 2 --hosts RemoteMachines /opt/RunJobs.sh

参数说明

-P
--print
    Display output as it arrives.  This option is of limited usefulness
    because output from different hosts are interleaved.

-i
--inline
    Display standard output and standard error as each host completes.

-p parallelism
--par parallelism
    Use the given number as the maximum number of concurrent connections.

-h host_file
--hosts host_file
    Read hosts from the given host_file.

基于ansible

# ansible --forks 2 -i RemoteMachines '*' -m command -a /opt/RunJobs.sh

参数说明

-f NUM, --forks=NUM
    Level of parallelism.  NUM is specified as an integer, the default is 5.

-i PATH, --inventory=PATH
    The PATH to the inventory hosts file, which defaults to /etc/ansible/hosts.

-m NAME, --module-name=NAME
    Execute the module called NAME.

-a 'ARGUMENTS', --args='ARGUMENTS'
    The ARGUMENTS to pass to the module.

命令模块执行命令名称后面的空格分隔的参数列表。给定的命令将在所有选定的节点上执行。它不会通过外壳进行处理,因此$ HOME之类的变量以及“ <”,“>,” |“和”&“之类的操作将不起作用。

您可以在Ad-Hoc命令简介中阅读更多内容

NB ansible不会切换到主机的下一组,直到所有的当前主机(“叉”)完成,因此它的并行度低PSSH(有可能增加它的一种方式,但我不知道) 。

这两种情况下RemoteMachines文件都看起来像这样:

[email protected]
[email protected]
[email protected]
[email protected]

远程机器的解决方案

RunJobs.sh重写为如下所示:

find FileDirectory -name 'Input_*' -print0 | xargs -0 -P 2 -n 1 ./Executable

说明

-0, --null
       Input items are terminated by a null character instead of by
       whitespace, and the quotes and backslash are not special (every
       character is taken literally).  Disables the end of file string,
       which is treated like any other argument.  Useful when input items
       might contain white space, quote marks, or backslashes.  The GNU find
       -print0 option produces input suitable for this mode.

-P max-procs, --max-procs=max-procs
       Run  up to max-procs  processes at a time; the default is 1.  If
       max-procs is 0, xargs will run as many processes as possible at a
       time.  Use the -n option or the -L option with -P; otherwise chances
       are  that  only  one  exec will be done.

 -n max-args, --max-args=max-args
       Use at most max-args arguments per command line.  Fewer than
       max-args arguments will be used if the size (see the -s option) is
       exceeded, unless the -x option is given, in which case xargs will
       exit.

nitro2k01基于GNU Parallel解决方案功能更强大,但是正如您所看到的,GNU xargs也不错。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法使用SSH运行一系列命令

来自分类Dev

git log命令显示一系列提交的输出?

来自分类Dev

从.bat文件非同步运行一系列命令

来自分类Dev

在ubuntu终端中执行一系列命令

来自分类Dev

从.bat文件非同步运行一系列命令

来自分类Dev

如何为一系列命令创建别名?

来自分类Dev

使用()和$()执行一系列命令的区别

来自分类Dev

对目录中的每个文件运行一系列命令

来自分类Dev

从一系列git命令中省略“ git”

来自分类Dev

对字段中的每个值执行一系列命令

来自分类Dev

对多个文件运行一系列命令

来自分类Dev

从脚本向新终端发送一系列命令

来自分类Dev

Perl-遍历一系列哈希问题

来自分类Dev

我的问题是关于 Google 表格循环遍历一系列单元格和排名分数

来自分类Dev

如果图像出现问题,如何使JavaScript旋转一系列图像

来自分类Dev

在Linux中的一系列命令中,是否可以通过SSH从一个终端链接到另一个终端?

来自分类Dev

一个接一个地运行一系列命令

来自分类Dev

循环一系列withAnimation函数

来自分类Dev

使用Turtle绘制一系列形状,但只有一个出现

来自分类Dev

如何创建一个简单的脚本(在Linux中)执行一系列命令?

来自分类Dev

使用来自一系列命令的派生输出到pstree -p命令的egrep

来自分类Dev

文字出现在影像悬停中,并带有一系列影像

来自分类Dev

高图表(柱形图):一系列的数据标签很少出现

来自分类Dev

获取的次@Category出现次数的计数在JUnit的一系列测试

来自分类Dev

在一系列Python中使用lambda删除特定时间以下的单词出现

来自分类Dev

Sed或AWK:每次出现模式后,在一系列行号之间添加行

来自分类Dev

计算一系列字符串在列表中出现的次数 - Python

来自分类Dev

创建以一系列文件作为输入执行命令(逗号分隔)

来自分类Dev

在一系列UNIX管道命令的中间使用$ EDITOR

Related 相关文章

  1. 1

    无法使用SSH运行一系列命令

  2. 2

    git log命令显示一系列提交的输出?

  3. 3

    从.bat文件非同步运行一系列命令

  4. 4

    在ubuntu终端中执行一系列命令

  5. 5

    从.bat文件非同步运行一系列命令

  6. 6

    如何为一系列命令创建别名?

  7. 7

    使用()和$()执行一系列命令的区别

  8. 8

    对目录中的每个文件运行一系列命令

  9. 9

    从一系列git命令中省略“ git”

  10. 10

    对字段中的每个值执行一系列命令

  11. 11

    对多个文件运行一系列命令

  12. 12

    从脚本向新终端发送一系列命令

  13. 13

    Perl-遍历一系列哈希问题

  14. 14

    我的问题是关于 Google 表格循环遍历一系列单元格和排名分数

  15. 15

    如果图像出现问题,如何使JavaScript旋转一系列图像

  16. 16

    在Linux中的一系列命令中,是否可以通过SSH从一个终端链接到另一个终端?

  17. 17

    一个接一个地运行一系列命令

  18. 18

    循环一系列withAnimation函数

  19. 19

    使用Turtle绘制一系列形状,但只有一个出现

  20. 20

    如何创建一个简单的脚本(在Linux中)执行一系列命令?

  21. 21

    使用来自一系列命令的派生输出到pstree -p命令的egrep

  22. 22

    文字出现在影像悬停中,并带有一系列影像

  23. 23

    高图表(柱形图):一系列的数据标签很少出现

  24. 24

    获取的次@Category出现次数的计数在JUnit的一系列测试

  25. 25

    在一系列Python中使用lambda删除特定时间以下的单词出现

  26. 26

    Sed或AWK:每次出现模式后,在一系列行号之间添加行

  27. 27

    计算一系列字符串在列表中出现的次数 - Python

  28. 28

    创建以一系列文件作为输入执行命令(逗号分隔)

  29. 29

    在一系列UNIX管道命令的中间使用$ EDITOR

热门标签

归档