Module: ZTK::SSH::Command
- Included in:
- ZTK::SSH
- Defined in:
- lib/ztk/ssh/command.rb
Overview
SSH Console Command Helpers
Instance Method Summary (collapse)
-
- (Object) console_command
Builds our SSH console command.
-
- (Object) proxy_command
Builds our SSH proxy command.
Instance Method Details
- (Object) console_command
Builds our SSH console command.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ztk/ssh/command.rb', line 8 def console_command process_keys verbosity = ((ENV['LOG_LEVEL'] == "DEBUG") ? '-vv' : '-q') command = Array.new # command << [ %(sshpass -p '#{config.password}') ] if config.password command << [ %(ssh) ] command << [ verbosity ] command << [ "-x" ] command << [ "-a" ] command << [ "-o", "UserKnownHostsFile=/dev/null" ] command << [ "-o", "StrictHostKeyChecking=no" ] command << [ "-o", "KeepAlive=yes" ] command << [ "-o", "ServerAliveInterval=60" ] command << [ "-o", %(ProxyCommand="#{proxy_command}") ] if config.proxy_host_name !config.keys.nil? and !config.keys.empty? and [config.keys].flatten.compact.each do |key| command << [ "-i", key ] end command << [ "-p", config.port ] if config.port command << "#{config.user}@#{config.host_name}" command = command.flatten.compact.join(' ') config.ui.logger.debug { "console_command(#{command.inspect})" } command end |
- (Object) proxy_command
Builds our SSH proxy command.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ztk/ssh/command.rb', line 34 def proxy_command !config.proxy_user and log_and_raise(SSHError, "You must specify an proxy user in order to SSH proxy.") !config.proxy_host_name and log_and_raise(SSHError, "You must specify an proxy host_name in order to SSH proxy.") process_keys verbosity = ((ENV['LOG_LEVEL'] == "DEBUG") ? '-vv' : '-q') command = Array.new # command << [ %(sshpass -p '#{config.proxy_password}') ] if config.proxy_password command << [ %(ssh) ] command << [ verbosity ] command << [ "-x" ] command << [ "-a" ] command << [ "-o", "UserKnownHostsFile=/dev/null" ] command << [ "-o", "StrictHostKeyChecking=no" ] command << [ "-o", "KeepAlive=yes" ] command << [ "-o", "ServerAliveInterval=60" ] !config.proxy_keys.nil? and !config.proxy_keys.empty? and [config.proxy_keys].flatten.compact.each do |proxy_key| command << [ "-i", proxy_key ] end command << [ "-p", config.proxy_port ] if config.proxy_port command << "#{config.proxy_user}@#{config.proxy_host_name}" command << "'/usr/bin/env nc %h %p'" command = command.flatten.compact.join(' ') config.ui.logger.debug { "proxy_command(#{command.inspect})" } command end |