[erlang-questions] Quick connect to another node with erl

278 views
Skip to first unread message

Ward Bekker (TTY)

unread,
Jan 20, 2013, 3:17:31 PM1/20/13
to erlang-q...@erlang.org
Hi,

I want to connect to the shell on node bar@localhost. My current solution (see below) needs some user switch commands. Is there a way using CL arguments? Couldn't find a mention in the erl man page.

Thx,

Ward

----------

localhost ward$ erl -sname foo
Erlang R15B02 (erts-5.9.2) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false] [dtrace]

Eshell V5.9.2  (abort with ^G)
(foo@localhost)1> net_adm:ping(bar@localhost).
pong
(foo@localhost)2> 
User switch command
 --> r bar@localhost
 --> c
Eshell V5.9.2  (abort with ^G)
(bar@localhost)1> 


Ward Bekker (TTY)

unread,
Jan 20, 2013, 3:21:36 PM1/20/13
to erlang-q...@erlang.org
Nevermind. Just found `remsh` ;-)

/W

Jachym Holecek

unread,
Jan 20, 2013, 3:16:20 PM1/20/13
to Ward Bekker (TTY), erlang-q...@erlang.org
# Ward Bekker (TTY) 2013-01-20:
> I want to connect to the shell on node bar@localhost. My current solution
> (see below) needs some user switch commands. Is there a way using CL
> arguments? Couldn't find a mention in the erl man page.

Yes, using -remsh, like this:

Terminal 1:
# erl -sname foo -setcookie abc
Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false]

Eshell V5.8.5 (abort with ^G)
(foo@taiga)1>

Terminal 2:
# erl -sname bar -setcookie abc -remsh foo@taiga
Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false]

Eshell V5.8.5 (abort with ^G)
(foo@taiga)1> node().
foo@taiga
(foo@taiga)2> nodes().
[bar@taiga]
(foo@taiga)3>

BR,
-- Jachym
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Loïc Hoguin

unread,
Jan 22, 2013, 5:05:33 PM1/22/13
to Tomas Morstein, erlang-q...@erlang.org
On 01/22/2013 11:02 PM, Tomas Morstein wrote:
> Dne neděle, 20. ledna 2013 21:16:20 UTC+1 Jachym Holecek napsal(a):

>
> # Ward Bekker (TTY) 2013-01-20:
> > I want to connect to the shell on node bar@localhost. My current
> solution
> > (see below) needs some user switch commands. Is there a way using CL
> > arguments? Couldn't find a mention in the erl man page.
>
> Yes, using -remsh, like this:
>
> Terminal 1:
> # erl -sname foo -setcookie abc
> Erlang R14B04 (erts-5.8.5) [source] [64-bit] [smp:4:4]
> [rq:4] [async-threads:0] [kernel-poll:false]
>
> Eshell V5.8.5 (abort with ^G)
>
>
> It's worth to note that `remsh' should be used with extra care, especially
> when it comes to connecting live production systems.
> Time by time, it happens (at least to me) that someone accidentally
> issues `q().' instead of ^G-q. The result is remote node shutdown what
> is usually not what we wanted to do, although `q().' is good habit
> otherwise :)
>
> That's why I would recommend you to use extra VM options to restrict
> the shell and block at least `q()' and friends (well, I've never seen
> anybody who accidentally typed `init:stop()' yet :-) ).

init:stop() seems to stop the local node, not the remote node.

> In production, we do it like this: `+Bi -stdlib restricted_shell
> shell_restriction_policy_mod'

Nice advice.

--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu

Tomas Morstein

unread,
Jan 22, 2013, 6:20:27 PM1/22/13
to Loïc Hoguin, erlang-q...@erlang.org

Are you sure? Depends on what you define as remote and local.
Everything you write is executed on the remote node which is
local from the point of view of the (remote) shell.

The way I think it works is that `remsh' creates just a new
shell on the remote node which is redirected to another
console, and should deliver the very same behaviour as if
you're directly on the remote machine's console and start
another shell job via ^G followed by `s' command.

At the other hand, if you make ^G and `s' on the "local"
node (that one which was started with -remsh), you can
get shell which is truly local to that secondary node.

If you know about any tricks how to detect the original
node which is just remsh'd somewhere, let me know, because
it may be useful for improving the restricted_shell module.

[I would like to have ability to issue `q().' only on
the master console and block it on all the others.
Now we have it that `q().' is disabled at all unless
you issue something like `shell_restriction_policy:unlock ()'
and then the `q()' becomes allowed.]


A little example at the end:

tmr@gersemi:~$ erl -sname foo -setcookie abc
Erlang R15B (erts-5.9) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9 (abort with ^G)
(foo@gersemi)1>
(foo@gersemi)1>
(foo@gersemi)1> node ().
foo@gersemi
(foo@gersemi)2>

tmr@gersemi:~$ erl -sname boo -setcookie abc -remsh foo@gersemi
Erlang R15B (erts-5.9) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9 (abort with ^G)
(foo@gersemi)1>
(foo@gersemi)1> node ().
foo@gersemi
(foo@gersemi)2>
User switch command
--> j
1* {foo@gersemi,shell,start,[]}
--> s
--> j
1 {foo@gersemi,shell,start,[]}
2* {shell,start,[]}
--> c 2
Eshell V5.9 (abort with ^G)
(boo@gersemi)1>
User switch command
--> c 1

(foo@gersemi)2>

Loïc Hoguin

unread,
Jan 22, 2013, 6:30:55 PM1/22/13
to Tomas Morstein, erlang-q...@erlang.org

No, you are right, I got confused by what happens when you use -eval at
the same time (which is ran locally). That explains it.

--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu

Reply all
Reply to author
Forward
0 new messages