Sha256: 415cc1ee17be8dd983d17136fced7075671170c82eeca78ab1ea2f53a6f14438

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

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

USAGE = <<HERE
  sshall
    -g groups

    E.g.,
      sshall -c "ls -l /" HostA HostB
        Indicate each host
      sshall -c "ls -l /" -g GroupA GroupB
        Indicate Hosts with group names
      sshall -c "ls -l /"
        Execute on all hosts when empty targets

      sshall HostA HostB
        Login each hosts when -c option is omitted.

      sshall -u USER -c "ls -l /"
        Login as USER
HERE

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

## option analysis
OPTIONS = {}
op = OptionParser.new
op.on("-c command"    , "--command=str"    , "Command to be sent."){|v| OPTIONS[:command] = 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)

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 = "ssh #{host} #{OPTIONS[:command]}"
  print "#####{command}####"
  puts
  system command unless OPTIONS[:test]
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
comana-0.1.3 bin/sshall
comana-0.1.2 bin/sshall
comana-0.1.1 bin/sshall
comana-0.1.0 bin/sshall
comana-0.0.10 bin/sshall