Peer Stritzinger
Peer Stritzinger

Reputation: 8372

Simplest way to inform a local erlang node from a shell command

I'm running a distributed erlang system with one node per machine.

Since DNS is not available I all start them with the same -sname param e.g.

erl -sname foo ...

A operating-system daemon has the feature to execute shell (/bin/sh) commands when a certain event occurs (when a USB stick is pugged into the system).

I'm looking for a simple way to call a function on the erlang node local on this machine with this shell command (taking further action after the USB stick was detected and mounted).

I was thinking of calling erl -sname bar from the shell and run some code that looks like

[_,Host] = string:tokens(atom_to_list(node()), "@"),
The_node = list_to_atom("foo@" ++ Host),
spawn(The_node, My_fun),

Is this the way to go? Or is starting a whole new erlang node overkill (won't be doing it often though)

Or is it better to talk a socket opened by gen_tcp, or read a named pipe.

Or any other suggestions?

BTW this is running on a Unix system.

Upvotes: 5

Views: 794

Answers (1)

I GIVE TERRIBLE ADVICE
I GIVE TERRIBLE ADVICE

Reputation: 9648

What you want to use is actually erl_call, an application that lets you contact currently distributed nodes and run arbitrary code.

erl_call makes it possible to start and/or communicate with a distributed Erlang node. It is built upon the erl_interface library as an example application. Its purpose is to use an Unix shell script to interact with a distributed Erlang node.

You can either give it commands, an escript or pretty much just code to evaluate and it will do it. You have more details and actual example in its documentation.

Upvotes: 9

Related Questions