i need run complex erlang module function from unix shell
rpc:call('node@example.com', mnesia, dirty_first, [mytable])
how can i do it?
UPD:
i make test.escript
chmod +x test.escript
#!/usr/lib64/erlang/bin/escript
%%! -name 'test@example.com'
main(_Args) ->
R = rpc:call('node@example.com', mnesia, dirty_first, [mytable]),
io:format("~p~n",[R]).
and receive {badrpc, nodedown}
but when run
erl -name test@example.com
1> rpc:call('node@example.com', mnesia, dirty_first, [mytable]).
{my, data}.
i mean it works, but howto make escript work proprely?
You can parse complex arguments with escript:
I think escript might be something worth looking into.
Edit: Some examples.
First for all examples: Start the remote node somewhere, somehow.
Escript
1: Create a file named
hello.escript
with contentNotice that the
%%! -sname foo@bar
identifies the node on the host (instead of creating nonode@nohost), allow setting the same cookie%%! -sname foo@duvel -setcookie KNKKCFPYMJUPIOLYPOAA
as target host which solves the problem of getting{badrpc,nodedown}
. Notice that the same statement holds for the following examples (erl_call, and -eval) where both the node name and cookie is set.2: Set the execution bit and run
Erl_call
1: run
Eval
1: run
This creates a shell which might not be what you want in this case.
I might mention that if both nodes are on the same host and using the same cookie default value, the cookie value for foo and bar don't have to be explicitly set like in the examples.
After doing these examples and reading your question again I think what I GIVE TERRIBLE ADVICE said will be your best choice, erl_call. I fell for the word "complex" in question title where imho escripts allow much more "complex" setups in a easy-to-read manner. The variable
_String
in the escript example holds the arguments to the script which allows you to both access input through shell and perform complex erlang operations in the EVM. But erl_call might be more straight forward if you already have logic in some other application and just need to make this simple call to an erlang node.If your problem is how to set the Erlang node in network mode (i.e. turn the node into a distributed node), you might want to do something like
where Sname is your wanted node name. Only after this can you start communicating to another node with e.g. rpc.
The erl_call application is exactly what you need:
See the examples for more details
You can use -eval flag of erl: