[erlang-questions] ct_ssh

Daniel Widgren daniel.widgren@REDACTED
Tue Dec 6 13:12:42 CET 2011


Hi!

I'm trying to use ct_ssh to test different machines to send commands to them.

My module looks like this.

-module(ssht).

-export([connect/1, session_open/2, send_cmd/1, session_close/2, disconnect/1]).

connect(Site) ->
    timer:sleep(1000),
    ct:get_config(Site),
    case ct_ssh:connect(Site, ssh) of
	{ok, A} ->
	    A;
	{error, _} ->
	    timer:sleep(50000),
	    connect(Site)
    end.

session_open(A, Timeout) ->
    {ok, B} = ct_ssh:session_open(A, Timeout),
    B.

send_cmd(Command) ->
    ct:log(log, "COMMAND: ~p", [Command]),
    A = connect(ts),
    B = session_open(A, infinity),
    {_,Data} = ct_ssh:send_and_receive(A,B, Command),
    session_close(A,B),
    disconnect(A),
    ct:log(log, "~s",[Data]),
    case Data of
	"cli: /tmp/cli: No such file or directory\n" ->
	    send_cmd(Command);
	_ ->
	    Data
    end.

session_close(A, B) ->
    ct_ssh:session_close(A, B).

disconnect(A) ->
    ct_ssh:disconnect(A).

Right now send_cmd does more then it should do.

But the idea is that I want it to connect to a device, send a command
using stream/tunnel. I can't use exec function for the environment
that I'm using. So my idea was to create a connection and stream the
commando in some way to the device. But now I get a timeout from
ct_ssh:send_and_receive.

I'm using R14B04.

regards,
Daniel



More information about the erlang-questions mailing list