运行N Erlang节点并使用bash脚本在每个节点内执行一行

Jua*_*rez 0 linux bash shell erlang nodes

TL; DR:如何向bash启动的程序发送一行(并可能在后台运行)?

你好!我已经尝试了很多来自那里的解决方案,但我无法将它们全部组合成一个可行的解决方案.

我想创建一个运行N Erlang节点的bash脚本,如:

for i in {1..N}:
    erl -name server$i@127.0.0.1 -setcookie secret
Run Code Online (Sandbox Code Playgroud)

我希望他们通过ping另一个节点来"连接"它们.为此,我们可以这样做:

erl -name some_server@127.0.0.1 -setcookie secret
(inside erlang)> net_adm:ping('another_server@127.0.0.1').
Run Code Online (Sandbox Code Playgroud)

但是,即使在单个节点上进行尝试,我也无法将这两者结合起来.

我试过了:

echo "net_adm:ping('another_server@127.0.0.1')." > erlang_command
cat erlang_command - | erl -name some_server@127.0.0.1 -setcookie secret

(i've had partial success with this one, i can run it manually but i couldn't make it to work to run in the background or in another terminal)
Run Code Online (Sandbox Code Playgroud)

要么

xterm -e "echo \"net_adm:ping('another_server@127.0.0.1').\"; cat erlang_command - | erl -name some_server@127.0.0.1 -setcookie secret"
Run Code Online (Sandbox Code Playgroud)

或者其他技巧如:

echo "net_adm:ping('another_server@127.0.0.1')." | erl -name some_server@127.0.0.1 -setcookie secret

-----

echo "net_adm:ping('another_server@127.0.0.1')." > /dev/stdin
erl -name some_server@127.0.0.1 -setcookie secret

-----

Some uses of nohup and & (can't remember these exactly, but got a similar experience)
nohup erl -name some_server@127.0.0.1 -setcookie secret &
Run Code Online (Sandbox Code Playgroud)

然而,这些要么不起作用,要么正确执行ping并完成我的erlang节点,我想继续运行.我错过了什么?谢谢!

Ric*_*rdC 5

将输入管道输入到erl shell中并不是执行短代码的好方法.使用类似的东西erl -noshell -name ... -setcookie ... -eval 'rpc:call(another_server@127.0.0.1, MODULE, FUNCTION, [ARGS]).'(将MODULE,FUNCTION和ARGS替换为你想做的任何事情),或者如果你想做一些比oneliner更长的事情,你可以写一个escript; 有关详细信息,请参阅http://erlang.org/doc/man/escript.html.