Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
227 lines (129 sloc) 5.87 KB

Module trooper_ssh

Trooper SSH is in charge of connect to the remote hosts using the SSH application.

Description

It lets to tropper 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.

Data Types

exit_status()


exit_status() = integer()

opt()


opt() = {opt_key(), opt_value()}

opt_key()


opt_key() = atom()

opt_value()


opt_value() = term()

opts()


opts() = [opt()]

reason()


reason() = atom() | string()

trooper_ssh()

abstract datatype: trooper_ssh()

Function Index

exec/2Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection.
exec/3Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection.
exec_long_polling/2Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection.
exec_long_polling/3Executes the command in background setting the current process as the receiver for the incoming information from the SSH connection.
get_pid/1Retrieves the PID from a trooper_ssh type data.
start/1Starts the SSH connection given the parameters.
start_link/1Starts the SSH connection given the parameters.
stop/1Stops the SSH connection.

Function Details

exec/2


exec(Trooper_ssh::trooper_ssh(), 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/3


exec(TrooperSSH::trooper_ssh(), 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/2


exec_long_polling(Trooper_ssh::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/3


exec_long_polling(TrooperSSH::trooper_ssh(), 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/1


get_pid(Trooper_ssh::trooper_ssh()) -> pid()

Retrieves the PID from a trooper_ssh type data.

start/1


start(Opts::opts()) -> {ok, trooper_ssh()} | {error, reason()}

Starts the SSH connection given the parameters.

start_link/1


start_link(Opts::opts()) -> {ok, trooper_ssh()} | {error, reason()}

Starts the SSH connection given the parameters.

stop/1


stop(Trooper_ssh::trooper_ssh()) -> ok

Stops the SSH connection.

You can’t perform that action at this time.