We are running an erlang program (ejabberd). Sometimes, we need to do health checks by connecting an erl shell to this running erlang program.

I am trying to script all this, and rather than typing erl -sname r -remsh .... and then, my command in the erlang shell, I'm looking for way to directly execute that command from my bash shell and get the output. Is this possible?

After Odobenus's answer, I wrote this little script:

#!/usr/bin/env escript
%%! -sname r -setcookie `cat ~ejabberd/.erlang.cookie`

main([]) -> 
    Res = rpc:call(ejabberd@xmpp,mnesia,info,[]),
    io:format("~p~n",[Res]).

The problem is that I get a "Node Down" Error, even though these are the exact same params I use to connect with erl: erl -sname r -remsh ejabberd@xmpp -setcookie `cat ~ejabberd/.erlang.cookie`

有帮助吗?

解决方案

you can write escript for that purpose http://www.erlang.org/doc/man/escript.html

kind of (for example tst.erl)

#!/usr/bin/env escript
%%! -sname r 

main([Cookie]) -> 
    erlang:set_cookie(node(),list_to_atom(Cookie)),
    Res = rpc:call(name@somenode,somemodule,somefunction,[]),
    io:format("~p~n",[Res]).

and call it from bash script

./tst.erl `cat verythatfile`

其他提示

The problem is in -sname parameter. Use full name -name node@host and everything will work

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top