multissh 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/multissh +6 -0
- data/lib/multissh/version.rb +3 -0
- data/lib/multissh.rb +34 -0
- data/lib/pretty_host.rb +60 -0
- data/multissh.gemspec +24 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e3b907d0a5db1045479392e24c6ed9c17b143b1f
|
4
|
+
data.tar.gz: bbaafc24d654c0c5be6db9bc828cfe6c8917f0bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b592f57ec81c6061c6da7aaa3f18a098dfd6dffbc7b13d49cd18451f3dd2e01947f883b539b9c67df67a2fb7a0692ebbaecd0a75d89cfa1690b7c4f4d9c99d65
|
7
|
+
data.tar.gz: b9b781b6effc1979970d3f26dc91484ba9ae197e7bc18463b9bf5983bd6f39b824d3d3752163071bc42415812016caad5d3bc69aac5ab33079b7d02f2005ec64
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jonas Tehler
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Multissh
|
2
|
+
|
3
|
+
Runs a ssh command on multiple hosts in parallel.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install multissh
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
multissh expects one or more hostnames on STDIN and the command and arguments to run as arguments to multissh.
|
12
|
+
|
13
|
+
Examples:
|
14
|
+
|
15
|
+
`echo foo.bar.com | multissh ls -l`
|
16
|
+
|
17
|
+
`cat hosts.txt | multissh "ls -l | grep foo"`
|
18
|
+
|
19
|
+
## Development
|
20
|
+
|
21
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
22
|
+
|
23
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jegt/multissh.
|
28
|
+
|
29
|
+
|
30
|
+
## License
|
31
|
+
|
32
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
33
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "multissh"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/multissh
ADDED
data/lib/multissh.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "multissh/version"
|
2
|
+
require 'sshkit'
|
3
|
+
require 'sshkit/dsl'
|
4
|
+
include SSHKit::DSL
|
5
|
+
require 'pretty_host'
|
6
|
+
|
7
|
+
module Multissh
|
8
|
+
def self.run!
|
9
|
+
|
10
|
+
command = ARGV.join(' ')
|
11
|
+
|
12
|
+
servers = []
|
13
|
+
begin
|
14
|
+
servers = STDIN.read_nonblock(4096).split(/[\s,]+/).map {|s| s.strip }
|
15
|
+
rescue IO::EAGAINWaitReadable => e
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
unless(servers.size > 0)
|
20
|
+
puts "Provide at least one hostname on stdin"
|
21
|
+
end
|
22
|
+
|
23
|
+
unless(command.strip.size > 0)
|
24
|
+
puts "Provide a command to run as argument"
|
25
|
+
end
|
26
|
+
|
27
|
+
SSHKit.config.output_verbosity = Logger::DEBUG
|
28
|
+
SSHKit.config.use_format :prettyhost
|
29
|
+
|
30
|
+
on servers do |host|
|
31
|
+
execute(command)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/pretty_host.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module SSHKit
|
2
|
+
|
3
|
+
module Formatter
|
4
|
+
|
5
|
+
class PrettyHost < Abstract
|
6
|
+
|
7
|
+
LEVEL_NAMES = %w{ DEBUG INFO WARN ERROR FATAL }.freeze
|
8
|
+
LEVEL_COLORS = [:black, :blue, :yellow, :red, :red].freeze
|
9
|
+
|
10
|
+
def write(obj)
|
11
|
+
if obj.kind_of?(SSHKit::LogMessage)
|
12
|
+
write_message(obj.verbosity, obj.to_s)
|
13
|
+
else
|
14
|
+
raise "write only supports formatting SSHKit::LogMessage, called with #{obj.class}: #{obj.inspect}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def log_command_start(command)
|
19
|
+
host_prefix = command.host.user ? "as #{colorize(command.host.user, :blue)}@" : 'on '
|
20
|
+
message = "Running #{colorize(command, :yellow, :bold)} #{host_prefix}#{colorize(command.host, :blue)}"
|
21
|
+
write_message(command.verbosity, message, command.host)
|
22
|
+
write_message(Logger::DEBUG, "Command: #{colorize(command.to_command, :blue)}", command.host)
|
23
|
+
end
|
24
|
+
|
25
|
+
def log_command_data(command, stream_type, stream_data)
|
26
|
+
color = \
|
27
|
+
case stream_type
|
28
|
+
when :stdout then :green
|
29
|
+
when :stderr then :red
|
30
|
+
else raise "Unrecognised stream_type #{stream_type}, expected :stdout or :stderr"
|
31
|
+
end
|
32
|
+
write_message(Logger::DEBUG, colorize("\t#{stream_data}".chomp, color), command.host)
|
33
|
+
end
|
34
|
+
|
35
|
+
def log_command_exit(command)
|
36
|
+
runtime = sprintf('%5.3f seconds', command.runtime)
|
37
|
+
successful_or_failed = command.failure? ? colorize('failed', :red, :bold) : colorize('successful', :green, :bold)
|
38
|
+
message = "Finished in #{runtime} with exit status #{command.exit_status} (#{successful_or_failed})."
|
39
|
+
write_message(command.verbosity, message, command.host)
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def format_message(verbosity, message, host=nil)
|
45
|
+
message = "[#{colorize(host, :green)}] #{message}" unless host.nil?
|
46
|
+
level = colorize(LEVEL_NAMES[verbosity].rjust(6), LEVEL_COLORS[verbosity])
|
47
|
+
"#{level} #{message}"
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def write_message(verbosity, message, host=nil)
|
53
|
+
original_output << "#{format_message(verbosity, message, host)}\n" if verbosity >= SSHKit.config.output_verbosity
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/multissh.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'multissh/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "multissh"
|
8
|
+
spec.version = Multissh::VERSION
|
9
|
+
spec.authors = ["Jonas Tehler"]
|
10
|
+
spec.email = ["jonas@tehler.se"]
|
11
|
+
|
12
|
+
spec.summary = %q{Run ssh commands in parallel on multiple hosts}
|
13
|
+
spec.homepage = "https://github.com/jegt/multissh"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "sshkit", ">= 1.14.0"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multissh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Tehler
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sshkit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.14.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.14.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- jonas@tehler.se
|
58
|
+
executables:
|
59
|
+
- multissh
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- exe/multissh
|
71
|
+
- lib/multissh.rb
|
72
|
+
- lib/multissh/version.rb
|
73
|
+
- lib/pretty_host.rb
|
74
|
+
- multissh.gemspec
|
75
|
+
homepage: https://github.com/jegt/multissh
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.6.12
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Run ssh commands in parallel on multiple hosts
|
99
|
+
test_files: []
|