jossh 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +78 -22
- data/lib/jossh/bin_handler.rb +5 -1
- data/lib/jossh/command_runner.rb +28 -7
- data/lib/jossh/templates/docopt.txt +1 -1
- data/lib/jossh/version.rb +1 -1
- metadata +25 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2392f4c98b9c8a6d7ccb5bc0480485e3b8caaf10
|
4
|
+
data.tar.gz: 76699c16469e9855283b62b88a4edf842e80194c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de3c0205fb8da77a2f3f4ec794e9711ef0a97bd4b2ba1597ec146098378cd441bcb2fe0a93fee412fb474d0f9594fdb6b19b5599122128e91a8de8df3cc960d8
|
7
|
+
data.tar.gz: 50559ec6d9797dec802eeb81390f9d0f6c85dbb6570444108b07506a052de8b0168ebe08616b53bc25407f7cf1ee6778ba64917e7c84fb81c4fa9e7e7335147f
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Jossh - Your SSH Buddy
|
|
8
8
|
|
9
9
|
**Jossh** is
|
10
10
|
|
11
|
-
- a command line utility for running local scripts and
|
11
|
+
- a command line utility for running local scripts and commands over SSH.
|
12
12
|
- a ruby library for easier and prettier SSH deployment and automation.
|
13
13
|
|
14
14
|
## Install
|
@@ -25,14 +25,15 @@ Or install manually
|
|
25
25
|
## Features
|
26
26
|
|
27
27
|
1. Allows running one or more commands over SSH.
|
28
|
-
2. Allows running
|
29
|
-
3.
|
30
|
-
4.
|
31
|
-
5. Uses a
|
32
|
-
6.
|
33
|
-
7.
|
34
|
-
8.
|
35
|
-
9.
|
28
|
+
2. Allows running local scripts remotely
|
29
|
+
3. Allows running a script on multiple hosts.
|
30
|
+
4. Has four commands: `ssh`, `ssh!`, `ssh_script` and `ssh_script!`. The 'bang' versions generate pretty and indented output.
|
31
|
+
5. Uses a single SSH connection.
|
32
|
+
6. Uses a simple hash for defining hosts.
|
33
|
+
7. Allows storing host specifications in a YAML file.
|
34
|
+
8. Supports all options available in `Net::SSH#start`.
|
35
|
+
9. Prints output Heroku-style.
|
36
|
+
10. Has a command line interface - `jossh <host> <script>`
|
36
37
|
|
37
38
|
## Command Line Usage
|
38
39
|
|
@@ -42,46 +43,47 @@ commands or a local script over SSH.
|
|
42
43
|
$ jossh -h
|
43
44
|
|
44
45
|
Jossh
|
45
|
-
|
46
|
+
|
46
47
|
Usage:
|
47
48
|
jossh <host> <script> [-- <arguments>...]
|
48
49
|
jossh -m | --make-hostfile
|
49
50
|
jossh -e | --edit-hostfile
|
50
51
|
jossh -l | --list
|
51
|
-
jossh -h | --help
|
52
|
+
jossh -h | --help
|
52
53
|
jossh -v | --version
|
53
|
-
|
54
|
+
|
54
55
|
Arguments:
|
55
56
|
<host>
|
56
57
|
can be:
|
57
|
-
- :symbol : in this case we will look in ./ssh_hosts.yml
|
58
|
+
- :symbol : in this case we will look in ./ssh_hosts.yml or ~/ssh_hosts.yml
|
58
59
|
- host : in this case we will use the current logged in user
|
59
60
|
- user@host
|
60
|
-
|
61
|
-
<script>
|
61
|
+
|
62
|
+
<script>
|
62
63
|
can be:
|
63
64
|
- a filename
|
64
65
|
- one or more direct command
|
65
|
-
|
66
|
+
|
66
67
|
<arguments>...
|
67
68
|
When specifying a filename as the <script>, you may also pass additional
|
68
|
-
arguments to it.
|
69
|
+
arguments to it.
|
69
70
|
Use $1 - $9 in your script file to work with these arguments.
|
70
71
|
Use $@ (or $*) to use the entire arguments string
|
71
|
-
|
72
|
+
|
72
73
|
Options:
|
73
|
-
-m --make-hostfile Generate a template ssh_hosts.yml
|
74
|
+
-m --make-hostfile Generate a template ssh_hosts.yml
|
74
75
|
-e --edit-hostfile Open the currently used ssh_hosts.yml file for editing
|
75
76
|
-l --list Show hosts in ./ssh_hosts.yml or ~/ssh_hosts.yml
|
76
77
|
-h --help Show this screen
|
77
78
|
-v --version Show version
|
78
|
-
|
79
|
-
Examples:
|
79
|
+
|
80
|
+
Examples:
|
80
81
|
jossh :production "git status"
|
81
82
|
jossh jack@server.com "cd ~ && ls -l"
|
82
83
|
jossh server.com deploy
|
83
84
|
jossh server.com rake -- db:migrate
|
84
85
|
|
86
|
+
---
|
85
87
|
|
86
88
|
## Library Usage
|
87
89
|
|
@@ -138,7 +140,7 @@ echo "-> Done"
|
|
138
140
|
|
139
141
|
See also: The [examples folder](https://github.com/DannyBen/jossh/tree/master/examples)
|
140
142
|
|
141
|
-
## Host
|
143
|
+
## Host Specification File
|
142
144
|
|
143
145
|
When using a :symbol as the host name, Jossh will look for a YAML
|
144
146
|
configuration file named `ssh_hosts.yml`. The file is expected to be either
|
@@ -162,4 +164,58 @@ You can ask Jossh to create a sample file for you by running:
|
|
162
164
|
|
163
165
|
$ jossh --make-hostfile
|
164
166
|
|
167
|
+
## Working with Multiple Hosts
|
168
|
+
|
169
|
+
Define multiple hosts in the `ssh_hosts.yml` file by simply providing an array
|
170
|
+
of other keys:
|
171
|
+
|
172
|
+
```yaml
|
173
|
+
:web01:
|
174
|
+
:host: web01.server.com
|
175
|
+
:user: admin
|
176
|
+
|
177
|
+
:web02:
|
178
|
+
:host: web02.server.com
|
179
|
+
:user: admin
|
180
|
+
|
181
|
+
:production:
|
182
|
+
- :web01
|
183
|
+
- :web02
|
184
|
+
```
|
185
|
+
|
165
186
|
See [ssh_hosts.example.yml](https://github.com/DannyBen/jossh/blob/master/ssh_hosts.example.yml) as an example.
|
187
|
+
|
188
|
+
## Writing Scripts
|
189
|
+
|
190
|
+
The scripts you execute with Jossh are simple shell scripts. These variables
|
191
|
+
are available to you inside the script:
|
192
|
+
|
193
|
+
### `$1 - $9 and $@ or $*`
|
194
|
+
|
195
|
+
When running through the command line and using the
|
196
|
+
`jossh <host> <script> -- <arguments>` syntax, these variables hold the
|
197
|
+
arguments.
|
198
|
+
|
199
|
+
`$@` and `$*` hold the entire arguments string.
|
200
|
+
|
201
|
+
Example:
|
202
|
+
```bash
|
203
|
+
# myscript
|
204
|
+
echo "-> Running requested rake task"
|
205
|
+
rake $@
|
206
|
+
```
|
207
|
+
|
208
|
+
And call it with:
|
209
|
+
`$ jossh :host myscript -- db:migrate`
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
### `%{key}`
|
214
|
+
When this syntax appears in your script, it will be replaced with any key
|
215
|
+
from the host configuration.
|
216
|
+
|
217
|
+
Example:
|
218
|
+
```bash
|
219
|
+
echo "-> Migrating database on %{host}"
|
220
|
+
rake db:migrate
|
221
|
+
```
|
data/lib/jossh/bin_handler.rb
CHANGED
@@ -71,7 +71,11 @@ module Jossh
|
|
71
71
|
if runner.active_hostfile
|
72
72
|
say "!txtgrn!Using: #{runner.active_hostfile}\n"
|
73
73
|
runner.ssh_hosts.each do |key, spec|
|
74
|
-
|
74
|
+
if spec.is_a? Hash
|
75
|
+
say " :#{key.to_s.ljust(14)} = !txtblu!#{spec[:user]}!txtrst!@!txtylw!#{spec[:host]}"
|
76
|
+
else
|
77
|
+
say " :#{key.to_s.ljust(14)} = !txtpur!#{spec.join '!txtrst!, !txtpur!'}"
|
78
|
+
end
|
75
79
|
end
|
76
80
|
else
|
77
81
|
say "!txtred!Cannot find ssh_hosts.yml or ~/ssh_hosts.yml"
|
data/lib/jossh/command_runner.rb
CHANGED
@@ -20,13 +20,12 @@ module Jossh
|
|
20
20
|
callback ||= method :simple_puts
|
21
21
|
script = script.join "\n" if script.is_a? Array
|
22
22
|
hostspec = load_spec(hostspec) if hostspec.is_a? Symbol
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Net::SSH.start( host, user, hostspec ) do |ssh|
|
27
|
-
ssh.exec! script do |_ch, stream, data|
|
28
|
-
callback.call data, stream
|
23
|
+
if hostspec.is_a? Array
|
24
|
+
hostspec.each do |spec|
|
25
|
+
execute_ssh_script spec, script, callback
|
29
26
|
end
|
27
|
+
else
|
28
|
+
execute_ssh_script hostspec, script, callback
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
@@ -63,6 +62,17 @@ module Jossh
|
|
63
62
|
|
64
63
|
private
|
65
64
|
|
65
|
+
def execute_ssh_script(hostspec, script, callback)
|
66
|
+
script = script % hostspec
|
67
|
+
host = hostspec.delete :host
|
68
|
+
user = hostspec.delete :user
|
69
|
+
Net::SSH.start( host, user, hostspec ) do |ssh|
|
70
|
+
ssh.exec! script do |_ch, stream, data|
|
71
|
+
callback.call data, stream
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
66
76
|
def simple_puts(data, stream)
|
67
77
|
if stream == :stderr
|
68
78
|
STDERR.puts data
|
@@ -72,7 +82,18 @@ module Jossh
|
|
72
82
|
end
|
73
83
|
|
74
84
|
def load_spec(key)
|
75
|
-
ssh_hosts[key]
|
85
|
+
hostspec = ssh_hosts[key]
|
86
|
+
return hostspec if hostspec.is_a? Hash
|
87
|
+
if hostspec.is_a? Array
|
88
|
+
hostspecs = []
|
89
|
+
hostspec.each do |inner_key|
|
90
|
+
inner_hostspec = load_spec(inner_key)
|
91
|
+
inner_hostspec or raise "Cannot find :#{inner_key} in :#{key}"
|
92
|
+
hostspecs << inner_hostspec
|
93
|
+
end
|
94
|
+
return hostspecs
|
95
|
+
end
|
96
|
+
raise "Cannot find :#{key}"
|
76
97
|
end
|
77
98
|
|
78
99
|
def load_ssh_hosts
|
@@ -11,7 +11,7 @@ Usage:
|
|
11
11
|
Arguments:
|
12
12
|
<host>
|
13
13
|
can be:
|
14
|
-
- :symbol : in this case we will look in ./ssh_hosts.yml
|
14
|
+
- :symbol : in this case we will look in ./ssh_hosts.yml or ~/ssh_hosts.yml
|
15
15
|
- host : in this case we will use the current logged in user
|
16
16
|
- user@host
|
17
17
|
|
data/lib/jossh/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jossh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -53,47 +53,61 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: runfile
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '5
|
61
|
+
version: '0.5'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '5
|
68
|
+
version: '0.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: run-gem-dev
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0.2'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0.2'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: minitest
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '5.8'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '5.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-reporters
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.1'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.1'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rake
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|