Sha256: ff99fab780bb04a35f59de1ff946294f977446944c3ea5d54f315d255603d090

Contents?: true

Size: 845 Bytes

Versions: 6

Compression:

Stored size: 845 Bytes

Contents

Run = Object.new
class << Run
  attr_reader :ssh

  def init(cmds, where)
    aster = "*" * 24
    puts "#{aster} #{where} #{aster}"
    @ssh = nil
    @cmds = cmds

    if where.include?("@")
      arr = where.split(":")
      host = arr.first
      dir = (arr.length > 1) ? arr.last : nil
    else
      host = nil
      dir = where
    end

    @cmds = "cd; cd #{dir}\n" + @cmds unless dir&.empty?
    @ssh = "ssh #{host}" if host
  end

  def info
    My.verbose("SSH", @ssh)
    My.verbose("cmds", @cmds)
  end

  def run
    here = "___EOS___"
    silent = Doit.options[:silent] ? ">/dev/null" : ""
    cmd = "cat <<'#{here}' | #{@ssh} bash -i -l #{silent} 2>&1"
    cmds = "#{cmd}\n#{@cmds}#{here}\n"

    if Doit.options[:noop]
      My.verbose("noop", cmds)
    else
      IO.popen(cmds) { |p| p.each { |f| puts f } }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
doit-1.0.9 lib/run.rb
doit-1.0.8 lib/run.rb
doit-1.0.7 lib/run.rb
doit-1.0.5 lib/run.rb
doit-1.0.4 lib/run.rb
doit-1.0.3 lib/run.rb