bash - GNU 并行错误 -onall
问题描述
我正在尝试通过 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 并仅在一台主机上运行该函数,则整个代码段都可以完美运行:
parallel -S host1,host2 “$(typeset -f f); f” ::: foo
给出输出:foo
任何关于可能出错的见解都会有所帮助:-)。我正在使用版本 20180422。
解决方案
您正在寻找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
推荐阅读
- ajax - f:ajax 不会渲染 h:panelGroup
- java - Cucumber/Gherkin - 在“背景”中放置“时间”术语是否可以接受?
- android - 如何从硬编码数据更改为数据库数据?
- php - Yii2如何将接收到的JSON数据保存到数据库中
- matlab - 为什么这个函数会产生“Inf”的值?
- java - 遍历HashMap
- django - 静态文件更改不会反映在浏览器刷新上
- sql - SQL 表单查询 - 根据复选框显示或不显示空列
- php - 如何在codeigniter中获取大于和小于数字的数据
- linux - 如果 column1 中的值重复,则 Awk 脚本对多列求和