我正在尝试通过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
如果我删除--- allall并仅在一台主机上运行该功能,则整个代码段均能正常工作:
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
然后尝试这三种不同的方法:
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