Sha256: 9d75ff1d2616a6d719d31a579b49b9de2d540591c653fca67530dc3d47edf002

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

#! /usr/bin/env ruby
# coding: utf-8

USAGE = <<HERE
  scpall
    scp from from on localhost to remotehost.

    E.g.,
      scpall -f from_file -t to_file HostA HostB
        Indicate each host
      scpall -f from_file -t to_file GroupA GroupB
        Indicate Hosts with group names
      scpall -f from_file -t to_file
        Execute on all hosts when empty targets

      scpall -u USER -f from_file -t to_file
        Login as USER
HERE

require "optparse"
require "pp"
require "rubygems"
require "comana"

## option analysis
OPTIONS = {}
op = OptionParser.new
op.on("-f from_file", "--from-file=str", "Copied file in a localhost."){|v| OPTIONS[:from_file] = v}
op.on("-t from_file", "--to-file=str", "File path in remotehosts."){|v| OPTIONS[:to_file] = v}
op.on("-g", "--group", "Interpret arguments as group name."){OPTIONS[:group] = true}
op.on("-u user", "--user=str"    , "User on remote host."){|v| OPTIONS[:user] = v}
op.on("-T", "--test"    , "Test mode; not execute."){OPTIONS[:test] = true}
op.parse!(ARGV)

unless OPTIONS[:from_file]
  puts "-f option is not set."
  puts USAGE; exit
end
unless OPTIONS[:to_file]
  puts "-t option is not set."
  puts USAGE; exit
end

hs = Comana::HostSelector.load_file
hosts = []
if ARGV.empty?
  hosts = hs.select_all
elsif OPTIONS[:group]
  ARGV.each do |tgt|
    hosts = hs.select_group(tgt)
  end
else
  hosts = ARGV
end

hosts.each do |host|
  host = "#{OPTIONS[:user]}@#{host}" if OPTIONS[:user]

  command = "scp #{OPTIONS[:from_file]} #{host}:#{OPTIONS[:to_file]}"
  print "#####{command}####"
  puts
  system command unless OPTIONS[:test]
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
comana-0.1.0 bin/scpall
comana-0.0.10 bin/scpall