Class: Shells::SshShell
Overview
Executes an SSH session with a host.
Valid options:
host-
The name or IP address of the host to connect to. Defaults to ‘localhost’.
port-
The port on the host to connect to. Defaults to 22.
user-
The user to login with. This option is required.
password-
The password to login with. If our public key is an authorized key on the host, the password is ignored for connection. The #sudo_exec method for bash-like shells will also use this password for elevation.
prompt-
The prompt used to determine when processes finish execution.
shell-
If set to :shell, then the default shell is executed. This is the default value. If set to :none, then no shell is executed, but a PTY is still created. If set to :no_pty, then no shell is executed and no PTY is created. If set to anything else, it is assumed to be the executable path to the shell you want to run.
quit-
If set, this defines the command to execute when quitting the session. The default is “exit” which will probably work most of the time.
retrieve_exit_code-
If set to a non-false value, then the default behavior will be to retrieve the exit code from the shell after executing a command. If set to a false or nil value, the default behavior will be to ignore the exit code from the shell. When retrieved, the exit code is stored in the
last_exit_codeproperty. This option can be overridden by providing an alternate value to theexecmethod on a case-by-case basis. on_non_zero_exit_code-
If set to :ignore (the default) then non-zero exit codes will not cause errors. You will still be able to check the
last_exit_codeproperty to determine if the command was successful. If set to :raise then non-zero exit codes will cause a Shells::NonZeroExitCode to be raised when a command exits with a non-zero return value. This option only comes into play whenretrieve_exit_codeis set to a non-false value. This option can be overridden by providing an alternate value to theexecmethod on a case-by-case basis. silence_timeout-
When a command is executing, this is the maximum amount of time to wait for any feedback from the shell. If set to 0 (or less) there is no timeout. Unlike
command_timeoutthis value resets every time we receive feedback. This option can be overridden by providing an alternate value to theexecmethod on a case-by-case basis. command_timeout-
When a command is executing, this is the maximum amount of time to wait for the command to finish. If set to 0 (or less) there is no timeout. Unlike
silence_timeoutthis value does not reset when we receive feedback. This option can be overridden by providing an alternate value to theexecmethod on a case-by-case basis. connect_timeout-
This is the maximum amount of time to wait for the initial connection to the SSH shell.
Shells::SshShell.new(
host: '10.10.10.10',
user: 'somebody',
password: 'super-secret'
) do |shell|
shell.exec('cd /usr/local/bin')
user_bin_files = shell.exec('ls -A1').split("\n")
@app_is_installed = user_bin_files.include?('my_app')
end
Direct Known Subclasses
Defined Under Namespace
Classes: FailedToRequestPty, FailedToStartShell
Instance Attribute Summary
Attributes inherited from ShellBase
#last_exit_code, #options, #output, #stderr, #stdout
Method Summary
Methods inherited from ShellBase
#change_quit, #exec, #exec_for_code, #exec_ignore_code, #initialize, #inspect, #line_ending, on_debug, #read_file, #run, #running?, #write_file
Constructor Details
This class inherits a constructor from Shells::ShellBase