-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This change allows the user to request a pseudo-tty: ``` require 'train' t = Train.create('ssh', host: '127.0.0.1', port: '2200', user: 'vagrant', password: 'vagrant', sudo: true, pty: true); puts t.connection.run_command("ls /") ``` While this allows passing the `requiretty` sudoer defaults of certain RedHat-ish distributions, it comes at the cost of having stderr and stdout merged together. The change includes a warning for this. The command above, for example, outputs: ``` <struct Train::Extras::CommandResult stdout="/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory\r\nbin dev home lib64\tmnt proc run\t shared sys usr var\r\nboot etc lib\t media\topt root sbin srv\t tmp vagrant\r\n", stderr="", exit_status=0> ``` For comparison, this is the output _without_ the PTY: ``` <struct Train::Extras::CommandResult stdout="bin\nboot\ndev\netc\nhome\nlib\nlib64\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nshared\nsrv\nsys\ntmp\nusr\nvagrant\nvar\n", stderr="/etc/profile.d/lang.sh: line 19: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory\n", exit_status=0> ``` Note how `ls` behaves differently -- in the presence of a PTY, it will prettify its output.
- Loading branch information
Showing
3 changed files
with
20 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ module Train::Transports | |
# | ||
# @author Fletcher Nichol <[email protected]> | ||
class SSHFailed < Train::TransportError; end | ||
class SSHPTYFailed < Train::TransportError; end | ||
|
||
# A Transport which uses the SSH protocol to execute commands and transfer | ||
# files. | ||
|
@@ -55,6 +56,7 @@ class SSH < Train.plugin(1) | |
option :connection_retry_sleep, default: 1 | ||
option :max_wait_until_ready, default: 600 | ||
option :compression, default: false | ||
option :pty, default: false | ||
|
||
option :compression_level do |opts| | ||
# on nil or false: set compression level to 0 | ||
|
@@ -98,6 +100,10 @@ def validate_options(options) | |
options[:auth_methods].push('password', 'keyboard-interactive') | ||
end | ||
|
||
if options[:pty] | ||
logger.warn('[SSH] PTY requested: stderr will be merged into stdout') | ||
end | ||
|
||
super | ||
self | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters