【问题标题】:GNU parallel errors on —onallGNU 并行错误 -onall
【发布时间】:2020-07-13 00:48:20
【问题描述】:

我正在尝试通过 ssh 发送一个 bash 函数并在所有远程主机上执行它。像这样的:

f() { echo $1; }
parallel -—onall -S host1,host2 “$(typeset -f f); f” ::: foo

但是,这会导致以下错误:

/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file
/bin/bash: \{\ : command not found
/bin/bash: \ \ \ \ echo\ \$1: command not found
/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file
/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file
/bin/bash: \{\ : command not found
/bin/bash: \ \ \ \ echo\ \$1: command not found
/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file

如果我删除 ---onall 并仅在一台主机上运行该功能,整个 sn-p 将完美运行:

parallel -S host1,host2 “$(typeset -f f); f” ::: foo

给出输出:foo

任何关于可能出现问题的见解都会有所帮助:-)。我使用的是 20180422 版本。

【问题讨论】:

  • 您正在使用一些有趣的引号或智能引号,就像某些 Windows 用户所说的那样。另外 afaik 您需要导出函数以通过 ssh 工作,但不确定。
  • 我不认为引用或导出是这里的问题,因为并行工作在 ssh 上运行良好,无需指定 —onall。仅当您直接在并行内部调用函数时才需要导出。 “$(排版-f f); f”首先由 bash 评估为:“f() { echo $1”}; f” 在并行运行之前。
  • 您可以随时通过shellcheck.net验证您的脚本
  • 刚刚做了。它发出的唯一警告是“f 似乎未使用”。为了安全起见,也尝试了导出。没用。

标签: bash shell ssh sh gnu-parallel


【解决方案1】:

您正在寻找env_parallel:

f() { echo foo; echo "$@"; }
env_parallel -S host1,host2 --onall f ::: a b c

如果你得到:

bash: /usr/bin/perl: Argument list too long
env_parallel: Error: Your environment is too big.
env_parallel: Error: You can try 3 different approaches:
env_parallel: Error: 1. Run 'env_parallel --session' before you set
env_parallel: Error:    variables or define functions.
env_parallel: Error: 2. Use --env and only mention the names to copy.
env_parallel: Error: 3. Try running this in a clean environment once:
env_parallel: Error:      env_parallel --record-env
env_parallel: Error:    And then use '--env _'
env_parallel: Error: For details see: man env_parallel

然后尝试以下 3 种不同的方法:

unset f
env_parallel --session
f() { echo foo; echo "$@"; }
env_parallel -S host1,host2 --onall f ::: a b c

或:

f() { echo foo; echo "$@"; }
env_parallel --env f -S host1,host2 --onall f ::: a b c

或:

unset f
env_parallel --record-env
f() { echo foo; echo "$@"; }
env_parallel --env _ -S host1,host2 --onall f ::: a b c

详情见:man env_parallel

或者升级到20180922:

parallel-20180922 --onall -S host1,host2 "$(typeset -f f); f" ::: a b c

【讨论】:

  • 我不想使用 env_parallel,因为我的环境非常大。更新并行修复它。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-29
  • 2016-01-10
  • 1970-01-01
  • 2014-04-20
  • 2012-08-31
  • 2018-06-09
相关资源
最近更新 更多