有两种方法可以做到这一点,根据 Erlang 节点的启动方式,这两种方法可能有效,也可能无效:
to_erlerl -remsh) over Erlang distributionEither way, you end up with an Erlang shell where you can inspect your tables.
If the Erlang node was started with the run_erl wrapper, then you can connect to the running node with to_erl. You can see the run_erl command used by running:
ps -C run_erl -fww
Run Code Online (Sandbox Code Playgroud)
For example, if the Erlang node was started with this command:
run_erl -daemon /my/erlang/node/tmp/ /my/erlang/node/log/ /my/erlang/node/start
Run Code Online (Sandbox Code Playgroud)
then the three paths in the command correspond to:
You want the first one for to_erl, so the command would be:
to_erl /my/erlang/node/tmp/
Run Code Online (Sandbox Code Playgroud)
Note the trailing slash! to_erl gets confused if it is missing.
To exit, type Ctrl-D.
If the Erlang node is running as a distributed node, and you know the secret "cookie", you can start another node and open a remote shell.
You need to know the node name of the running node, and also whether it's running with "long" or "short" node names.
In a "long" node name, the host part is a fully qualified domain name or an IP address, but in a "short" node name, the host part is just a host name, without dots. If the Erlang node was started with the -name option, it's using long node names, and if it was started with the -sname option, it's using short node names. If neither option was used, it's not a distributed node and it's not possible to connect to it.1
And the host name might be explicit or implicit in the command. If the command looks like one of these, you already know the exact node name:
erl -name myerlangnode@mymachine.example.com
erl -sname myerlangnode@mymachine
Run Code Online (Sandbox Code Playgroud)
But if the -name or -sname option only specifies the "bare" node name, you'll need to figure out what host name it chose to start with:
erl -name myerlangnode # node name is actually myerlangnode@mymachine.example.com
erl -sname myerlangnode # node name is actually myerlangnode@mymachine
Run Code Online (Sandbox Code Playgroud)
When one Erlang node connects to another, both nodes need to have the same "cookie" configured, otherwise the handshake will fail. The cookie can either be read from the file .erlang.cookie in the home directory of the user that the Erlang node is running as, or set explicitly with the -setcookie command when starting the node.
So now we know:
-name or -sname (i.e. long or short node name)-setcookieNow we can connect! We need to start a temporary Erlang node that:
-name or -sname, according to what the running node was started with-setcookie option as the running node, or runs as the same user to access the same .erlang.cookie file-remsh ("remote shell") to connect to the running node.-hidden to avoid being seen as part of the Erlang clusterSo something like this:
erl -hidden -name mytmpnode -setcookie secret -remsh myerlangnode@mymachine.example.com
erl -hidden -sname mytmpnode -setcookie secret -remsh myerlangnode@mymachine
Run Code Online (Sandbox Code Playgroud)
This should open a shell on the running node. You can tell by looking at the prompt, which should tell you the node name:
(myerlangnode@mymachine)1>
Run Code Online (Sandbox Code Playgroud)
If it doesn't show the right node name, see the question Erlang remote shell not working.
To exit, type Ctrl-g and then q.
Once you have an Erlang shell, you can inspect the tables. Use ets:all() or dets:all() to list the existing tables. For ETS, you can then use ets:tab2list, which shows all entries in a table:
ets:tab2list(my_table).
Run Code Online (Sandbox Code Playgroud)
For DETS, you can use dets:match_object with the '_' wildcard pattern:
dets:match_object(my_table, '_').
Run Code Online (Sandbox Code Playgroud)
1 Except if the node was started as a non-distributed node and later turned into a distributed node with net_kernel:start.
| 归档时间: |
|
| 查看次数: |
364 次 |
| 最近记录: |