module SSH_Utils
Attributes
server[R]
servers[RW]
Public Instance Methods
_show_cmd(cmd)
click to toggle source
# File lib/ssh-utils.rb, line 106 def _show_cmd cmd if @opts[:norun] || $norun talkf "(norun) %s\n", cmd elsif @opts[:debug] || $debug || @opts[:verbose] || $verbose talkf "--> %s\n", cmd end end
as(user, opts = {}) { || ... }
click to toggle source
as USER, :with => ENVARLIST, :debug => [true|false], :norun => [true|false]
# File lib/ssh-utils.rb, line 78 def as user, opts = {} @user = user merge_opts_with_env opts yield if block_given? end
merge_env(opts)
click to toggle source
merge_env
opts
merge envars. :with => ENVARS_TO_ADD, :without => ENVARS_TO_EXCLUDE
:with => %w(PATH RUBYLIB) :without => %w(PATH)
Removes the :with and :without keys from the opts hash
# File lib/ssh-utils.rb, line 44 def merge_env opts @envars = @@default_envars if opts.key?(:with) @envars.concat(opts[:with]).uniq! opts.delete(:with) end if opts.key?(:without) @envars -= opts[:without] opts.delete(:without) end end
merge_opts(opts = {})
click to toggle source
# File lib/ssh-utils.rb, line 32 def merge_opts opts = {} @opts ||= {} @opts.merge!(opts) unless opts.empty? end
merge_opts_with_env(opts = {})
click to toggle source
merge_opts_with_env
opts
Invokes merge_env
, then merge_opts
# File lib/ssh-utils.rb, line 60 def merge_opts_with_env opts = {} merge_env (opts = opts.dup) merge_opts opts end
on(servers, opts = {}) { |server| ... }
click to toggle source
on SERVERLIST, :with => %w(PATH RUBYLIB), :debug => [true|false], :norun => [true|false]
# File lib/ssh-utils.rb, line 67 def on servers, opts = {} merge_opts_with_env opts (@servers = servers).each do |server| @server = server talk("--> Running block for server #{server}..") if @opts[:debug] || $debug yield server end end
remote_run(cmd)
click to toggle source
remote_run
COMMAND run the remote command
# File lib/ssh-utils.rb, line 117 def remote_run cmd ssh = ssh_command(cmd) _show_cmd ssh system(ssh) unless @opts[:norun] || $norun end
Also aliased as: run_remotely
remote_run_with_output(cmd, opts = {})
click to toggle source
# File lib/ssh-utils.rb, line 125 def remote_run_with_output cmd, opts = {} merge_opts_with_env opts ssh = ssh_command cmd _show_cmd ssh out = nil IO.popen(ssh) {|f| out = f.read } out end
ssh_command(cmd)
click to toggle source
# File lib/ssh-utils.rb, line 91 def ssh_command cmd ssh = "ssh -A" ssh += " -u #{@user}" unless @user.nil? ssh += " #{@server}" @envars.each do |env| # explicit values in the options list override the environment values val = @opts.key?(env) ? @opts[env] : ENV[env] if !(val.nil? || val.empty?) ssh += sprintf(" %s='%s'", env, val.gsub("'", "\'")) end end ssh += " " + cmd.to_s ssh end
with(env, opts = {}) { || ... }
click to toggle source
with ENVARLIST, :VAR1 => value, :debug => …
# File lib/ssh-utils.rb, line 86 def with env, opts = {} merge_opts_with_env opts yield if block_given? end