Skip to content

Instantly share code, notes, and snippets.

@fsword
Created May 26, 2014 06:54
Show Gist options
  • Save fsword/d2a185d5de6a27cd3f0e to your computer and use it in GitHub Desktop.
Save fsword/d2a185d5de6a27cd3f0e to your computer and use it in GitHub Desktop.
验证ssh库的缺省配置能获得多少数据?
-module(ssh_test).
-export([go/0]).
go() ->
ssh:start(),
Host = "127.0.0.1",
Port = 22,
Options = [{user,"john"},
{silently_accept_hosts, true},
{user_interaction, false},
{connect_timeout, 2000}
],
Cmd = "/home/john/test.rb",
{ok, Conn} = ssh:connect(Host, Port, Options),
{ok, Chl} = ssh_connection:session_channel(Conn, infinity),
success = ssh_connection:exec(Conn,Chl,Cmd,infinity),
get_result(Conn,Chl).
get_result(Conn,Chl) ->
receive
{ssh_cm, Conn, {closed,Chl}} ->
io:format("closed~n");
{ssh_cm, Conn, {exit_signal, Chl, _ExitSignal, _ErrMsg, _Lang}} ->
io:format("exit_signal~n"),
get_result(Conn,Chl);
{ssh_cm, Conn, {data, Chl, _Type_code, Data}} ->
io:format("Data: ~ts", [Data]),
get_result(Conn,Chl);
{ssh_cm, Conn, {exit_status, Chl, _ExitStatus}} ->
io:format("exit~n"),
get_result(Conn,Chl);
{ssh_cm, Conn, {eof,Chl}} ->
io:format("eof~n"),
get_result(Conn,Chl)
end.
#!/usr/bin/env ruby
$stdout.sync = true
1000.times do |i|
puts "#{i}: #{'hello' * 100}"
sleep(rand/2)
end
@fsword
Copy link
Author

fsword commented May 26, 2014

执行结果
......
Data: 128: hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello
Data: 129: hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohe #在这里就卡住了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment