dtot 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +21 -0
  4. data/bin/dtot +90 -0
  5. metadata +62 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d9de31d14ef0494aca7ce60fbadda0d44bf76b19cea09b63657849403a8d956b
4
+ data.tar.gz: c097a7d1bba7b205047b0f9437a17d56291d4e78f2277bb44dfe3e41393fe55d
5
+ SHA512:
6
+ metadata.gz: b8311e3d62db168b94a334c7da578b7c0132e7add48e7d2ed43eaa12cff9e61fd8814ae494ea8ddc7cb5b4aabbf0a18257034605bebf2caa237d97537e85abcc
7
+ data.tar.gz: 3d03d11b9a6edc526c44e49d5ce5e2fa6568fb9df2f5048a418761357767e693dda45028c3cb81d1030995a74cc53d34c403647adbfe953e50cff5f2e1b9f530
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Josh Campbll
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # About
2
+ Do This On That (dtot) sequentially runs plain shell commands on one or more hosts in the specified order. You need SSH public key authentication already setup on the target hosts. You can run a single command across multiple hosts by running dtot from the command line with arguments, or you can feed dtot a list of commands and hosts by using some helper files. See the Usage section below for more information.
3
+
4
+ # Usage
5
+ ```gem install dtot```
6
+ <br>
7
+ ```dtot --help```
8
+
9
+ Specify commands followed by multiple hosts to run commands, sequentially, on all hosts in specified order. Uses the currently logged in, local user as the username on the target systems.
10
+
11
+ ```dtot -c uptime,w,"ls -lah /" -w host1,host2,host3```<br>
12
+ ```dtot -c "sudo yum update -y" -w host1,host2```
13
+
14
+ Or, use "do this" and "on that" files:<br>
15
+ ```dtot -d do_this.txt -o on_that.txt```
16
+
17
+ ## do_this.txt
18
+ Each command should be on one line; commands are run sequentially, not in parrallel (by design). See the example do_this.txt in the examples directory of this repository.
19
+
20
+ ## on_that.txt
21
+ On each line put the username with access followed by a space and then the hostname. You should have public key authentication already setup on the host for the user specified. See the example on_that.txt in the examples directory of this repository.
data/bin/dtot ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Josh Campbell
4
+ # https://github.com/irlrobot/dothisonthat
5
+ #
6
+ # This is v1.0.1
7
+ #
8
+
9
+ require 'rubygems'
10
+ require 'net/ssh'
11
+ require 'optparse'
12
+
13
+ def ssh_exec(hostname, username, commands)
14
+ Net::SSH.start(hostname, username) do |ssh|
15
+ commands.each do |command|
16
+ puts command
17
+ result = ssh.exec!(command)
18
+ puts result
19
+ puts "--------------------------------------------------"
20
+ end # commands.each
21
+ end # Net::SSH.start
22
+ end # ssh_exec
23
+
24
+ options = {}
25
+ OptionParser.new do |opts|
26
+ opts.banner = "Usage: ./dothisonthat.rb [options]"
27
+
28
+ opts.on("-h", "--help", "Show this message") do
29
+ puts opts
30
+ exit
31
+ end
32
+
33
+ opts.on("-c", "--command COMMAND1,COMMAND2", Array, "Specify commands to run, use with -w") do |c|
34
+ options[:commands] = c
35
+ end
36
+
37
+ opts.on("-w", "--hosts HOST1,HOST2", Array, "Hosts to run the command on, use with -c") do |w|
38
+ options[:hosts] = w
39
+ end
40
+
41
+ opts.on("-d", "--do_this FILE_PATH", String, "Specify a command file, use with -o") do |d|
42
+ options[:command_file] = d
43
+ end
44
+
45
+ opts.on("-o", "--on_that FILE_PATH", String, "Specify a server file, use with -d") do |o|
46
+ options[:server_file] = o
47
+ end
48
+ end.parse!(ARGV)
49
+
50
+ current_user = ENV['USER']
51
+
52
+ if options[:commands] && options[:hosts]
53
+ options[:hosts].each do |host|
54
+ puts "--------------------------------------------------"
55
+ puts "--------------------------------------------------"
56
+ puts "Connecting to #{host}"
57
+ puts "--------------------------------------------------"
58
+ begin
59
+ puts "Running #{options[:commands]}"
60
+ puts "--------------------------------------------------"
61
+ ssh_exec(host, current_user, options[:commands])
62
+ rescue
63
+ puts "Can't connect to #{host}. Check host or credentials."
64
+ end
65
+ end
66
+ elsif options[:command_file] && options[:server_file]
67
+ File.open(options[:server_file]).each_line do |host|
68
+ username = host.split[0]
69
+ hostname = host.split[1]
70
+ puts "--------------------------------------------------"
71
+ puts "--------------------------------------------------"
72
+ puts "Connecting to #{hostname}"
73
+ puts "--------------------------------------------------"
74
+
75
+ commands = []
76
+ File.open(options[:command_file]).each_line do |command|
77
+ commands.push(command.chomp)
78
+ end
79
+
80
+ begin
81
+ puts "Running '#{commands}'"
82
+ puts "--------------------------------------------------"
83
+ ssh_exec(hostname, username, commands)
84
+ rescue
85
+ puts "Can't connect to #{host.split[1]}. Check host or credentials."
86
+ end
87
+ end
88
+ else
89
+ puts "Invalid arguments, use --help for usage information."
90
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dtot
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Josh Campbell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ssh
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ description: Do This On That (dtot) sequentially runs commands on one or more hosts
28
+ in the specified order.
29
+ email: josh@userdel.com
30
+ executables:
31
+ - dtot
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE.txt
36
+ - README.md
37
+ - bin/dtot
38
+ homepage: https://github.com/irlrobot/dothisonthat
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.0.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.7.6
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Do This On That
62
+ test_files: []