[erlang-questions] Running an erl program on a remote machine

Garrett Smith <>
Tue May 24 00:24:32 CEST 2011

Hi Philippe,

On Mon, May 23, 2011 at 9:55 AM,  <> wrote:
> Hi,
> I have been asked to write a script which runs database commands on one of n
> mirror machines. The name of the machine the commands should be run on is
> contained in a DNS alias called, say, THE_CURRENT_MACHINE. In other words,
> if the THE_CURRENT_MACHINE alias resolves to machineA.company.com,
>  then the script should be run on that machine, if it resolves to
>  machineB.company.com, it should run on machine b, etc.
> I have thought of several ways of doing the above:
> - run a PERL script at a set time each day on a machine which I will call
> machinex, which resolves the THE_CURRENT_MACHINE alias, connects to
> it via SSH and runs the database commands. The disadvantage of
> this solution is that, if machinex is down, the PERL script won't be run.

IMO, this is by far the best option if you don't already have an agent
framework (e.g. Erlang nodes, Fabric, Puppet) running on each of the
database servers. Running and maintaining agents on servers is
nontrivial when compared to firing off a script over ssh.

Have the script available on more than one machine for fail over --
which is a drop dead simple problem for rsync, git, scp, etc.

> - run a PERL script at a set time each day on machines A and B (and C and D...)
> makes sure that the current machine's name is equal to THE_CURRENT_MACHINE value,
> and, if that is the case, runs the database commands.
> The disadvantage of this solution is that if I have 10 machines, I
> must duplicate the script on those ten machines.

This requires you to sync on something. If you plan on using DNS, you
need to make sure your DNS clients are in fact getting the
latest/consistent records for the "current machine". If you've worked
with DNS, you know it's forte is not consistency :)

> - write an Erlang program which create a remote process on THE_CURRENT_MACHINE that
> runs the database commands, if it is feasible. Once again, if machinex is down,
> the program won't be run.

Even if you wanted to use this a foray into distributed Erlang, I
think you could find a better application.

> - write an Erlang script which will run as a daemon on machines A, B, C...
> which checks every second if the time matches the time at which the database
> commands should be triggered, and, if that is the case, run them.

This sounds like cron, which you should probably use if you want to
run something on each server. But I still think an ssh command is the
obvious choice.

> If I had never heard of Erlang and of its alleged "spawn a remote process" capabilities,
> I would opt for solution 2 above. If you fellows have a better solution, please let me know.
> Philippe


More information about the erlang-questions mailing list