em-ssh 0.3.0 → 0.3.2

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 (3) hide show
  1. data/README.md +91 -82
  2. data/lib/em-ssh/version.rb +1 -1
  3. metadata +1 -1
data/README.md CHANGED
@@ -3,56 +3,59 @@ Em-ssh is a net-ssh adapter for EventMachine. For the most part you can take any
3
3
 
4
4
  Em-ssh is not associated with the Jamis Buck's [net-ssh](http://net-ssh.github.com/) library. Please report any bugs with em-ssh to [https://github.com/simulacre/em-ssh/issues](https://github.com/simulacre/em-ssh/issues)
5
5
  ##Installation
6
- gem install em-ssh
6
+ gem install em-ssh
7
7
 
8
8
  ##Synopsis
9
- EM.run do
10
- EM::Ssh.start(host, user, :password => password) do |connection|
11
- connection.errback do |err|
12
- $stderr.puts "#{err} (#{err.class})"
9
+
10
+ ```ruby
11
+ EM.run do
12
+ EM::Ssh.start(host, user, :password => password) do |connection|
13
+ connection.errback do |err|
14
+ $stderr.puts "#{err} (#{err.class})"
15
+ end
16
+ connection.callback do |ssh|
17
+ # capture all stderr and stdout output from a remote process
18
+ ssh.exec!('uname -a').tap {|r| puts "\nuname: #{r}"}
19
+
20
+ # capture only stdout matching a particular pattern
21
+ stdout = ""
22
+ ssh.exec!("ls -l /home") do |channel, stream, data|
23
+ stdout << data if stream == :stdout
13
24
  end
14
- connection.callback do |ssh|
15
- # capture all stderr and stdout output from a remote process
16
- ssh.exec!('uname -a').tap {|r| puts "\nuname: #{r}"}
17
-
18
- # capture only stdout matching a particular pattern
19
- stdout = ""
20
- ssh.exec!("ls -l /home") do |channel, stream, data|
21
- stdout << data if stream == :stdout
22
- end
23
- puts "\n#{stdout}"
24
-
25
- # run multiple processes in parallel to completion
26
- ssh.exec('ping -c 1 www.google.com')
27
- ssh.exec('ping -c 1 www.yahoo.com')
28
- ssh.exec('ping -c 1 www.rakuten.co.jp')
29
-
30
- #open a new channel and configure a minimal set of callbacks, then wait for the channel to finishes (closees).
31
- channel = ssh.open_channel do |ch|
32
- ch.exec "/usr/local/bin/ruby /path/to/file.rb" do |ch, success|
33
- raise "could not execute command" unless success
34
-
35
- # "on_data" is called when the process writes something to stdout
36
- ch.on_data do |c, data|
37
- $stdout.print data
38
- end
39
-
40
- # "on_extended_data" is called when the process writes something to stderr
41
- ch.on_extended_data do |c, type, data|
42
- $stderr.print data
43
- end
44
-
45
- ch.on_close { puts "done!" }
25
+ puts "\n#{stdout}"
26
+
27
+ # run multiple processes in parallel to completion
28
+ ssh.exec('ping -c 1 www.google.com')
29
+ ssh.exec('ping -c 1 www.yahoo.com')
30
+ ssh.exec('ping -c 1 www.rakuten.co.jp')
31
+
32
+ #open a new channel and configure a minimal set of callbacks, then wait for the channel to finishes (closees).
33
+ channel = ssh.open_channel do |ch|
34
+ ch.exec "/usr/local/bin/ruby /path/to/file.rb" do |ch, success|
35
+ raise "could not execute command" unless success
36
+
37
+ # "on_data" is called when the process writes something to stdout
38
+ ch.on_data do |c, data|
39
+ $stdout.print data
40
+ end
41
+
42
+ # "on_extended_data" is called when the process writes something to stderr
43
+ ch.on_extended_data do |c, type, data|
44
+ $stderr.print data
46
45
  end
46
+
47
+ ch.on_close { puts "done!" }
47
48
  end
48
-
49
- channel.wait
50
-
51
- ssh.close
52
- EM.stop
53
49
  end
54
- end
55
- end
50
+
51
+ channel.wait
52
+
53
+ ssh.close
54
+ EM.stop
55
+ end
56
+ end
57
+ end
58
+ ```
56
59
 
57
60
  See [http://net-ssh.github.com/ssh/v2/api/index.html](http://net-ssh.github.com/ssh/v2/api/index.html)
58
61
 
@@ -61,53 +64,59 @@ See [http://net-ssh.github.com/ssh/v2/api/index.html](http://net-ssh.github.com/
61
64
  Em-ssh provides an expect-like shell abstraction layer on top of net-ssh in EM::Ssh::Shell
62
65
 
63
66
  ### Example
64
- require 'em-ssh/shell'
65
- EM.run {
66
- EM::Ssh::Shell.new(host, ENV['USER'], "") do |shell|
67
- shell.callback do
68
- shell.expect('~]$ ')
69
- shell.expect('~]$ ','uname -a')
70
- shell.expect('~]$ ')
71
- shell.expect('~]$ ', '/sbin/ifconfig -a')
72
- EM.stop
73
- end
74
- shell.errback do
75
- puts "error: #{err} (#{err.class})"
76
- EM.stop
77
- end
78
- end
79
- }
67
+
68
+ ```ruby
69
+ require 'em-ssh/shell'
70
+ EM.run do
71
+ EM::Ssh::Shell.new(host, ENV['USER'], "") do |shell|
72
+ shell.callback do
73
+ shell.expect('~]$ ')
74
+ shell.expect('~]$ ','uname -a')
75
+ shell.expect('~]$ ')
76
+ shell.expect('~]$ ', '/sbin/ifconfig -a')
77
+ EM.stop
78
+ end
79
+ shell.errback do
80
+ puts "error: #{err} (#{err.class})"
81
+ EM.stop
82
+ end
83
+ end
84
+ end
85
+ ```
80
86
 
81
87
  ### Run Multiple Commands in Parallel
82
- require 'em-ssh/shell'
83
- EM.run do
84
- EM::Ssh::Shell.new(host, ENV['USER'], '') do |shell|
85
- shell.errback do |err|
86
- puts "error: #{err} (#{err.class})"
87
- EM.stop
88
- end
89
88
 
90
- shell.callback do
91
- commands.clone.each do |command|
92
- mys = shell.split # provides a second session over the same connection
93
- mys.on(:closed) do
94
- commands.delete(command)
95
- EM.stop if commands.empty?
96
- end
89
+ ```ruby
90
+ require 'em-ssh/shell'
91
+ EM.run do
92
+ EM::Ssh::Shell.new(host, ENV['USER'], '') do |shell|
93
+ shell.errback do |err|
94
+ puts "error: #{err} (#{err.class})"
95
+ EM.stop
96
+ end
97
+
98
+ shell.callback do
99
+ commands.clone.each do |command|
100
+ mys = shell.split # provides a second session over the same connection
101
+ mys.on(:closed) do
102
+ commands.delete(command)
103
+ EM.stop if commands.empty?
104
+ end
97
105
 
98
- puts("waiting for: #{waitstr.inspect}")
99
- # When given a block, Shell#expect does not 'block'
100
- mys.expect(waitstr) do
101
- puts "sending #{command.inspect} and waiting for #{waitstr.inspect}"
102
- mys.expect(waitstr, command) do |result|
103
- puts "#{mys} result: '#{result}'"
104
- mys.close
105
- end
106
+ puts("waiting for: #{waitstr.inspect}")
107
+ # When given a block, Shell#expect does not 'block'
108
+ mys.expect(waitstr) do
109
+ puts "sending #{command.inspect} and waiting for #{waitstr.inspect}"
110
+ mys.expect(waitstr, command) do |result|
111
+ puts "#{mys} result: '#{result}'"
112
+ mys.close
106
113
  end
107
114
  end
108
115
  end
109
116
  end
110
117
  end
118
+ end
119
+ ```
111
120
 
112
121
  ## Other Examples
113
122
  See bin/em-ssh for an example of a basic replacement for system ssh.
@@ -1,5 +1,5 @@
1
1
  module EventMachine
2
2
  class Ssh
3
- VERSION='0.3.0'
3
+ VERSION='0.3.2'
4
4
  end # class::Ssh
5
5
  end # module::EventMachine
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: