View Source trooper_ssh (trooper v0.4.2)

Trooper SSH is in charge of connect to the remote hosts using the SSH application. It lets to trooper to execute commands on those remote servers and returns the output.

You have two ways to run commands: simple and long polling.

Simple means you send a command (i.e. uname -r) and you get a sync response to your request.

       trooper_ssh:exec(Trooper, "uname -r").
       % {ok, 0, <<"3.16.0-0.bpo.4-amd64">>}

Long polling means you send a command (i.e. ping -c 15 127.0.0.1) and your process starts to receive all of the output of that remote process:

       trooper_ssh:exec_long_polling(Trooper, "ping -c 15 127.0.0.1").
       % ok
       flush().
       % {continue, <<"PING 127.0.0.1 (127.0.0.1) 56(84) "...>>}

Until you receive the closed event.

Summary

Functions

Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection.

Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection. This function let us to use the format and args way to create the command to be execute in the remote server.

Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection.

Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection. This function let us to use the format and args way to create the command to be execute in the remote server.

Retrieves the PID from a trooper_ssh type data.

Starts the SSH connection given the parameters.

generates SSH channel to run the commands in the same context.

Starts the SSH connection given the parameters.

Stops the SSH connection.

stops a ssh channel.

Starts and stops a SSH connection to be available only for the closure passed as second parameter.

Types

exit_status/0

-type exit_status() :: integer().

opt/0

-type opt() :: {opt_key(), opt_value()}.

opt_key/0

-type opt_key() :: atom().

opt_value/0

-type opt_value() :: term().

opts/0

-type opts() :: [opt()].

reason/0

-type reason() :: atom() | string().

trooper_ssh/0

-opaque trooper_ssh()

trooper_ssh_chan/0

-opaque trooper_ssh_chan()

Functions

exec(Trooper_ssh, Command)

-spec exec(trooper_ssh() | trooper_ssh_chan(), Command :: string()) ->
              {ok, exit_status(), binary()} | {error, reason()}.

Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection.

exec(TrooperSSH, CommandFormat, Args)

-spec exec(trooper_ssh() | trooper_ssh_chan(), CommandFormat :: string(), Args :: [term()]) ->
              {ok, exit_status(), binary()} | {error, reason()}.

Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection. This function let us to use the format and args way to create the command to be execute in the remote server.

exec_long_polling(Trooper_ssh, Command)

-spec exec_long_polling(trooper_ssh(), Command :: string()) -> pid().

Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection.

exec_long_polling(TrooperSSH, CommandFormat, Args)

-spec exec_long_polling(trooper_ssh() | trooper_ssh_chan(), CommandFormat :: string(), Args :: [term()]) ->
                           pid().

Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection. This function let us to use the format and args way to create the command to be execute in the remote server.

get_pid(Trooper_ssh)

-spec get_pid(trooper_ssh()) -> pid().

Retrieves the PID from a trooper_ssh type data.

start(Opts)

-spec start(opts()) -> {ok, trooper_ssh()} | {error, reason()}.

Starts the SSH connection given the parameters.

start_chan(Trooper_ssh)

-spec start_chan(trooper_ssh()) -> {ok, trooper_ssh_chan()}.

generates SSH channel to run the commands in the same context.

start_link(Opts)

-spec start_link(opts()) -> {ok, trooper_ssh()} | {error, reason()}.

Starts the SSH connection given the parameters.

stop(Trooper_ssh)

-spec stop(trooper_ssh()) -> ok.

Stops the SSH connection.

stop_chan(Trooper_ssh_chan)

-spec stop_chan(trooper_ssh_chan()) -> ok.

stops a ssh channel.

transaction(Opts, Fun)

-spec transaction(opts(), fun((trooper_ssh()) -> any())) -> any().

Starts and stops a SSH connection to be available only for the closure passed as second parameter.