sshelper 0.0.1 → 0.1.0
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.
- data/README.md +64 -9
- data/bin/sshelper +24 -4
- data/lib/sshelper.rb +14 -6
- data/lib/sshelper/string.rb +25 -0
- data/lib/sshelper/version.rb +1 -1
- data/resources/template.json +16 -0
- data/sshelper.gemspec +2 -1
- metadata +20 -2
data/README.md
CHANGED
@@ -1,24 +1,79 @@
|
|
1
1
|
# Sshelper
|
2
2
|
|
3
|
-
|
3
|
+
This gem is supposed to make your life easier if you have to do a lot of repetitive tasks over SSH. If you are sick
|
4
|
+
of doing the constant ```ssh user@example.org```, ```cd /opt/path/to/something```, ```./start.sh```
|
5
|
+
etc, then this tool is for you!
|
6
|
+
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
7
|
-
|
10
|
+
Install it as follows:
|
8
11
|
|
9
|
-
gem
|
12
|
+
$ gem install sshelper
|
10
13
|
|
11
|
-
|
14
|
+
## Usage
|
12
15
|
|
13
|
-
|
16
|
+
After installation, you will have to create a '.sshelper.json' file in your home directory:
|
14
17
|
|
15
|
-
|
18
|
+
$ touch ~/.sshelper.json
|
16
19
|
|
17
|
-
|
20
|
+
Or, you can use the built in functionality to generate a template:
|
18
21
|
|
19
|
-
|
22
|
+
$ sshelper -t
|
23
|
+
|
24
|
+
Open it in your favorite editor:
|
25
|
+
|
26
|
+
$ nano ~/.sshelper.json
|
27
|
+
|
28
|
+
And use the following structure to add labels:
|
29
|
+
```
|
30
|
+
{
|
31
|
+
"my_label1": {
|
32
|
+
"description": "View the content of the newest file on example.org and test.com",
|
33
|
+
"servers": [
|
34
|
+
{
|
35
|
+
"host": "example.org",
|
36
|
+
"port": 22,
|
37
|
+
"user": "root"
|
38
|
+
},
|
39
|
+
{
|
40
|
+
"host": "test.com",
|
41
|
+
"port": 1234,
|
42
|
+
"user": "eddy"
|
43
|
+
}
|
44
|
+
],
|
45
|
+
"commands": [
|
46
|
+
"ls -l",
|
47
|
+
"cat `ls -1rt | tail -1`"
|
48
|
+
]
|
49
|
+
},
|
50
|
+
"my_label2": {
|
51
|
+
"description": "List 1 file on example.org"
|
52
|
+
"servers": [
|
53
|
+
{
|
54
|
+
"host": "example.org",
|
55
|
+
"port": 22,
|
56
|
+
"user": "root"
|
57
|
+
}
|
58
|
+
],
|
59
|
+
"commands": [
|
60
|
+
"ls -1"
|
61
|
+
]
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
After you have added a configuration file with labels, servers and commands, you can do stuff like this:
|
68
|
+
|
69
|
+
$ sshelper my_label1
|
70
|
+
|
71
|
+
This will execute all commands defined under "my_label1" on all servers defined under that same block! Talking about
|
72
|
+
enhancing your workflow...
|
73
|
+
|
74
|
+
To list all the labels you have defined, you can do:
|
20
75
|
|
21
|
-
|
76
|
+
$ sshelper -l
|
22
77
|
|
23
78
|
## Contributing
|
24
79
|
|
data/bin/sshelper
CHANGED
@@ -2,15 +2,38 @@
|
|
2
2
|
|
3
3
|
require 'sshelper'
|
4
4
|
require 'optparse'
|
5
|
+
require 'fileutils'
|
5
6
|
|
6
|
-
|
7
|
+
trap("SIGINT") { puts "\nExiting...\n"; exit! }
|
7
8
|
|
8
9
|
options = {}
|
9
10
|
|
10
11
|
global = OptionParser.new do |opts|
|
11
12
|
opts.banner = "Usage: sshelper [your_label]\n\n"
|
13
|
+
opts.on("-l", "--labels", "Show all labels") do
|
14
|
+
puts "Usage: sshelper [your_label]\n\n"
|
15
|
+
puts "Labels:"
|
16
|
+
Sshelper.prepare!
|
17
|
+
Sshelper.configuration.each do |key, value|
|
18
|
+
puts "\t#{key.to_s}: #{value.description}"
|
19
|
+
end
|
20
|
+
puts "\n\n"
|
21
|
+
exit!
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("-t", "--template", "Place a template configuration at ~/.sshelper.json") do
|
25
|
+
template = IO.read(File.expand_path('../../resources/template.json', __FILE__))
|
26
|
+
File.open(File.expand_path("~/.sshelper.json"), "w") { |f| f.write template }
|
27
|
+
exit!
|
28
|
+
end
|
12
29
|
end
|
13
30
|
|
31
|
+
global.order!
|
32
|
+
command = ARGV.shift
|
33
|
+
puts global if command.nil?
|
34
|
+
|
35
|
+
Sshelper.prepare!
|
36
|
+
|
14
37
|
subcommands = {}
|
15
38
|
|
16
39
|
Sshelper.configuration.each do |key, value|
|
@@ -19,9 +42,6 @@ Sshelper.configuration.each do |key, value|
|
|
19
42
|
end
|
20
43
|
end
|
21
44
|
|
22
|
-
global.order!
|
23
|
-
command = ARGV.shift
|
24
|
-
puts global if command.nil?
|
25
45
|
subcommands[command].order! if subcommands.member? command
|
26
46
|
|
27
47
|
Sshelper.execute_label command
|
data/lib/sshelper.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require "sshelper/version"
|
2
2
|
require "sshelper/hash"
|
3
|
+
require "sshelper/string"
|
3
4
|
require "net/ssh"
|
5
|
+
require "net/ssh/telnet"
|
4
6
|
require "json"
|
5
7
|
require "fileutils"
|
8
|
+
require "socket"
|
6
9
|
|
7
10
|
module Sshelper
|
8
11
|
@config
|
@@ -37,13 +40,18 @@ module Sshelper
|
|
37
40
|
|
38
41
|
@config[label].servers.each do |server|
|
39
42
|
port = (server.include?("port") ? server.port : 22)
|
40
|
-
Net::SSH.start(server.host, server.user, :port => port)
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
ssh = Net::SSH.start(server.host, server.user, :port => port)
|
44
|
+
s = Net::SSH::Telnet.new("Session" => ssh)
|
45
|
+
puts "Logged in".pink
|
46
|
+
@config[label].commands.each do |command|
|
47
|
+
puts "\nExecuting: #{command}".red
|
48
|
+
puts '#### OUTPUT ####'.blue
|
49
|
+
puts "#{s.cmd(command).split("\n").join("\n ~> ")}"
|
50
|
+
puts '#### END ####'.blue
|
44
51
|
end
|
45
|
-
|
46
|
-
|
52
|
+
s.close
|
53
|
+
ssh.close
|
54
|
+
end
|
47
55
|
end
|
48
56
|
|
49
57
|
def self.configuration
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class String
|
2
|
+
def colorize(color_code)
|
3
|
+
"\e[#{color_code}m#{self}\e[0m"
|
4
|
+
end
|
5
|
+
|
6
|
+
def red
|
7
|
+
colorize(31)
|
8
|
+
end
|
9
|
+
|
10
|
+
def green
|
11
|
+
colorize(32)
|
12
|
+
end
|
13
|
+
|
14
|
+
def yellow
|
15
|
+
colorize(33)
|
16
|
+
end
|
17
|
+
|
18
|
+
def blue
|
19
|
+
colorize(34)
|
20
|
+
end
|
21
|
+
|
22
|
+
def pink
|
23
|
+
colorize(35)
|
24
|
+
end
|
25
|
+
end
|
data/lib/sshelper/version.rb
CHANGED
data/sshelper.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshelper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -61,6 +61,22 @@ dependencies:
|
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: net-ssh
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.1.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.1.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: net-ssh-telnet
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
65
81
|
none: false
|
66
82
|
requirements:
|
@@ -93,7 +109,9 @@ files:
|
|
93
109
|
- bin/sshelper
|
94
110
|
- lib/sshelper.rb
|
95
111
|
- lib/sshelper/hash.rb
|
112
|
+
- lib/sshelper/string.rb
|
96
113
|
- lib/sshelper/version.rb
|
114
|
+
- resources/template.json
|
97
115
|
- spec/spec_helper.rb
|
98
116
|
- spec/sshelper_spec.rb
|
99
117
|
- sshelper.gemspec
|