rsh 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/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +14 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/rsh.rb +127 -0
- data/rsh.gemspec +57 -0
- data/spec/rsh_spec.rb +7 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +96 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Pavel Argentov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
= rsh
|
2
|
+
|
3
|
+
Author:: Pavel Argentov (argentoff at gmail dot com)
|
4
|
+
|
5
|
+
Here's a simple tiny wrapper which alows me to use rsh shell command in PORO
|
6
|
+
(Plain Old Ruby Object) style. For all details see Rsh class rdoc.
|
7
|
+
|
8
|
+
This gem was developed and tested on FreeBSD 8.1. If you find any
|
9
|
+
incompatibilities and/or are ready to help me fix the problem feel free to
|
10
|
+
write me on the public email listed above.
|
11
|
+
|
12
|
+
== Copyright
|
13
|
+
|
14
|
+
Copyright (c) 2010 Pavel Argentov. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rsh"
|
8
|
+
gem.summary = %Q{Simple wrapper for rsh cli command.}
|
9
|
+
gem.description = %Q{All freenixes (e.g. Linux, *BSD, etc.) have 'rsh' command.
|
10
|
+
Here's the gem wrapping call to this command and handling the command's result/output.}
|
11
|
+
gem.email = "argentoff@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/argent-smith/rsh"
|
13
|
+
gem.authors = ["Pavel Argentov"]
|
14
|
+
gem.rubyforge_project = "rsh"
|
15
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
20
|
+
rubyforge.doc_task = "rdoc"
|
21
|
+
end
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'spec/rake/spectask'
|
27
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
30
|
+
end
|
31
|
+
|
32
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
33
|
+
spec.libs << 'lib' << 'spec'
|
34
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
35
|
+
spec.rcov = true
|
36
|
+
end
|
37
|
+
|
38
|
+
task :spec => :check_dependencies
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "rsh #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/rsh.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# = UNIX rsh(1) wrapper class
|
2
|
+
#
|
3
|
+
# Creates and operates an 'rsh' command call instance. Parameters to rsh may
|
4
|
+
# be specified through either constructor or attribute accessors. Result of
|
5
|
+
# rsh execution (_String_) is either returned in functional style (<tt>##execute</tt> method call)
|
6
|
+
# or in special attribute, _result_.
|
7
|
+
#
|
8
|
+
# == Synopsis
|
9
|
+
#
|
10
|
+
# require 'rsh'
|
11
|
+
#
|
12
|
+
# rsh = Rsh.new(:host => "c7206", :ruser => "bill",
|
13
|
+
# :command => "show clock")
|
14
|
+
#
|
15
|
+
# rsh.execute do |line| puts line end
|
16
|
+
#
|
17
|
+
# 18:30:46.799 MSD Fri Oct 22 2010
|
18
|
+
#
|
19
|
+
# == See also
|
20
|
+
#
|
21
|
+
# % man 1 rsh
|
22
|
+
#
|
23
|
+
class Rsh
|
24
|
+
# path to rsh program, +String+
|
25
|
+
attr_reader :executable
|
26
|
+
|
27
|
+
# result +String+
|
28
|
+
attr_reader :result
|
29
|
+
|
30
|
+
# remote server hostname or IP, +String+
|
31
|
+
attr_accessor :host
|
32
|
+
|
33
|
+
# remote command, +String+
|
34
|
+
attr_accessor :command
|
35
|
+
|
36
|
+
# remote username, +String+
|
37
|
+
attr_accessor :ruser
|
38
|
+
|
39
|
+
# rsh timeout, +Integer+ (see man 1 rsh)
|
40
|
+
attr_accessor :to
|
41
|
+
|
42
|
+
# boolean knob for <tt>/dev/null</tt> redirection; see man rsh for further
|
43
|
+
# information
|
44
|
+
attr_accessor :nullr
|
45
|
+
|
46
|
+
# The Constructor. Checks the presence of rsh in the system (running,
|
47
|
+
# naturally, 'which rsh') and prepares the command to be run with <tt>##execute</tt>.
|
48
|
+
# rsh CLI arguments are either having default values, being collected from constructor
|
49
|
+
# call or specified via accessors.
|
50
|
+
#
|
51
|
+
# call-seq:
|
52
|
+
# new(:host => "hostname",
|
53
|
+
# :command => "example.sh",
|
54
|
+
# :ruser => "jack",
|
55
|
+
# :to => 5,
|
56
|
+
# :nullr => true)
|
57
|
+
#
|
58
|
+
# Argument defaults are:
|
59
|
+
# :host => "localhost"
|
60
|
+
# :command => ""
|
61
|
+
# :ruser => "nobody"
|
62
|
+
# :to => 3
|
63
|
+
# :nullr => false
|
64
|
+
#
|
65
|
+
# Arguments hash is optional.
|
66
|
+
#
|
67
|
+
def initialize(args={})
|
68
|
+
args = {:host => "localhost",
|
69
|
+
:command => "",
|
70
|
+
:ruser => "nobody",
|
71
|
+
:to => 3,
|
72
|
+
:nullr => false}.merge!(args)
|
73
|
+
begin
|
74
|
+
open("| which rsh") do |io|
|
75
|
+
@executable = io.gets.chomp
|
76
|
+
end
|
77
|
+
rescue => detail
|
78
|
+
raise "FATAL: Could not find rsh executable!"
|
79
|
+
end
|
80
|
+
|
81
|
+
@host = args[:host]
|
82
|
+
@command = args[:command]
|
83
|
+
@ruser = args[:ruser]
|
84
|
+
@to = args[:to]
|
85
|
+
@nullr = args[:nullr]
|
86
|
+
@result = ""
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Executes rsh command using previously collected arguments.
|
91
|
+
#
|
92
|
+
# If given a block, calls it for each line received from rsh output
|
93
|
+
# (parameter _line_).
|
94
|
+
#
|
95
|
+
# Returns:: the complete rsh output as one _String_. The result is also
|
96
|
+
# stored and available via _result_ attribute.
|
97
|
+
#
|
98
|
+
def execute
|
99
|
+
@result = ""
|
100
|
+
open "|#{executable} #{"-n" if @nullr} -l#{ruser} -t#{to} #{host} #{command}" do |io|
|
101
|
+
io.each do |line|
|
102
|
+
yield(line) if block_given?
|
103
|
+
@result << line
|
104
|
+
end
|
105
|
+
end
|
106
|
+
@result
|
107
|
+
end
|
108
|
+
|
109
|
+
#
|
110
|
+
# :section: Example
|
111
|
+
#
|
112
|
+
# This is an example of rsh in action usin interactive Ruby.
|
113
|
+
#
|
114
|
+
# irb(main):001:0> require 'rsh'
|
115
|
+
# => true
|
116
|
+
#
|
117
|
+
# irb(main):002:0> rsh = Rsh.new(:host => "c7206", :ruser => "bill",
|
118
|
+
# :command => "show clock")
|
119
|
+
# => #<Rsh:0x2853f390 @ruser="bill", @executable="/usr/bin/rsh", @result="", @command="show clock", @nullr=false, @host="c7206", @to=3>
|
120
|
+
#
|
121
|
+
# irb(main):003:0> rsh.execute do |line| puts line end
|
122
|
+
#
|
123
|
+
# 18:30:46.799 MSD Fri Oct 22 2010
|
124
|
+
# => "\r\n18:30:46.799 MSD Fri Oct 22 2010\n"
|
125
|
+
#
|
126
|
+
|
127
|
+
end
|
data/rsh.gemspec
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rsh}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Pavel Argentov"]
|
12
|
+
s.date = %q{2010-10-22}
|
13
|
+
s.description = %q{All freenixes (e.g. Linux, *BSD, etc.) have 'rsh' command.
|
14
|
+
Here's the gem wrapping call to this command and handling the command's result/output.}
|
15
|
+
s.email = %q{argentoff@gmail.com}
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/rsh.rb",
|
28
|
+
"rsh.gemspec",
|
29
|
+
"spec/rsh_spec.rb",
|
30
|
+
"spec/spec.opts",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/argent-smith/rsh}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubyforge_project = %q{rsh}
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Simple wrapper for rsh cli command.}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/spec_helper.rb",
|
41
|
+
"spec/rsh_spec.rb"
|
42
|
+
]
|
43
|
+
|
44
|
+
if s.respond_to? :specification_version then
|
45
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
end
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
data/spec/rsh_spec.rb
ADDED
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsh
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Pavel Argentov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-22 00:00:00 +04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 9
|
34
|
+
version: 1.2.9
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: |-
|
38
|
+
All freenixes (e.g. Linux, *BSD, etc.) have 'rsh' command.
|
39
|
+
Here's the gem wrapping call to this command and handling the command's result/output.
|
40
|
+
email: argentoff@gmail.com
|
41
|
+
executables: []
|
42
|
+
|
43
|
+
extensions: []
|
44
|
+
|
45
|
+
extra_rdoc_files:
|
46
|
+
- LICENSE
|
47
|
+
- README.rdoc
|
48
|
+
files:
|
49
|
+
- .document
|
50
|
+
- .gitignore
|
51
|
+
- LICENSE
|
52
|
+
- README.rdoc
|
53
|
+
- Rakefile
|
54
|
+
- VERSION
|
55
|
+
- lib/rsh.rb
|
56
|
+
- rsh.gemspec
|
57
|
+
- spec/rsh_spec.rb
|
58
|
+
- spec/spec.opts
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/argent-smith/rsh
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project: rsh
|
90
|
+
rubygems_version: 1.3.7
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Simple wrapper for rsh cli command.
|
94
|
+
test_files:
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/rsh_spec.rb
|