tinyssh 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tinyssh +2 -7
- data/lib/tinyssh.rb +12 -13
- data/lib/tinysshoptparse.rb +8 -8
- metadata +4 -4
data/bin/tinyssh
CHANGED
@@ -35,12 +35,7 @@ def main(options)
|
|
35
35
|
|
36
36
|
HOST.each_with_index do |host, index|
|
37
37
|
T << Thread.new {
|
38
|
-
session = Net::SSH.conn(host, options.user,
|
39
|
-
:port => options.port,
|
40
|
-
:password => password,
|
41
|
-
:keys => options.keys,
|
42
|
-
:timeout => options.timeout,
|
43
|
-
:passphrase => passphrase.chomp)
|
38
|
+
session = Net::SSH.conn(host, options.user, :port => options.port, :password => password, :keys => options.keys, :timeout => options.timeout, :passphrase => passphrase.chomp)
|
44
39
|
|
45
40
|
if session.class == String
|
46
41
|
OUTPUT[index] = session % host
|
@@ -60,7 +55,7 @@ def main(options)
|
|
60
55
|
end
|
61
56
|
|
62
57
|
OUTPUT.keys.sort.each do |k|
|
63
|
-
|
58
|
+
puts OUTPUT[k]
|
64
59
|
end
|
65
60
|
|
66
61
|
if options.output_file != nil
|
data/lib/tinyssh.rb
CHANGED
@@ -10,16 +10,15 @@ module Net::SSH
|
|
10
10
|
begin
|
11
11
|
return Net::SSH.start(*options)
|
12
12
|
rescue Timeout::Error
|
13
|
-
return "\n#{OUTPUT_TITLE}\nHost : %s [ "
|
13
|
+
return "\n#{OUTPUT_TITLE}\nHost : %s [ #{"Connecting Timeout".red} ] !\n"
|
14
14
|
rescue Errno::EHOSTUNREACH
|
15
|
-
return "\n#{OUTPUT_TITLE}\nHost : %s [ "
|
15
|
+
return "\n#{OUTPUT_TITLE}\nHost : %s [ #{"Unreachable".red} ] !\n"
|
16
16
|
rescue Errno::ECONNREFUSED
|
17
|
-
return "\n#{OUTPUT_TITLE}\nHost : %s [ "
|
17
|
+
return "\n#{OUTPUT_TITLE}\nHost : %s [ #{"Connection Refused".red} ] !\n"
|
18
18
|
rescue Net::SSH::AuthenticationFailed
|
19
|
-
return "\n#{OUTPUT_TITLE}\nHost : %s [ "
|
20
|
-
rescue
|
21
|
-
|
22
|
-
return "\n#{OUTPUT_TITLE}\nHost : %s [ " + "Name or Server not know".red + " ] !\n"
|
19
|
+
return "\n#{OUTPUT_TITLE}\nHost : %s [ #{"Authentication Failure".red} ] !\n"
|
20
|
+
rescue
|
21
|
+
return "\n#{OUTPUT_TITLE}\nHost : %s [ #{"Name or Server not know".red} ] !\n"
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
@@ -27,23 +26,23 @@ end
|
|
27
26
|
class Net::SSH::Connection::Session
|
28
27
|
def run(cmd)
|
29
28
|
output = self.exec!(cmd)
|
30
|
-
|
29
|
+
"\n#{output}#{OUTPUT_TITLE}\nExecute \"#{cmd}\" at #{host}: [ #{"OK".green} ]\n"
|
31
30
|
rescue
|
32
|
-
|
31
|
+
"\n#{OUTPUT_TITLE}\nExecute \"#{cmd}\" at #{host}: [ #{"FAIL".red} ] !\n"
|
33
32
|
end
|
34
33
|
|
35
34
|
def up(src, dst)
|
36
35
|
self.scp.upload!(src, dst, :recursive => true)
|
37
|
-
|
36
|
+
"\n#{OUTPUT_TITLE}\nUpload #{host}:#{src} to #{dst}: [ #{"OK".green} ] !\n"
|
38
37
|
rescue
|
39
|
-
|
38
|
+
"\n#{OUTPUT_TITLE}\nUpload #{host}:#{src} to #{dst}: [ #{"FAIL".red} ] !\n"
|
40
39
|
end
|
41
40
|
|
42
41
|
def dl(src, dst)
|
43
42
|
self.scp.download!(src, dst, :recursive => true)
|
44
|
-
|
43
|
+
"\n#{OUTPUT_TITLE}\nDownload #{host}:#{src} to #{dst}: [ #{"OK".green} ] !\n"
|
45
44
|
rescue
|
46
|
-
|
45
|
+
"\n#{OUTPUT_TITLE}\nDownload #{host}:#{src} to #{dst}: [ #{"FAIL".red} ] !\n"
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
data/lib/tinysshoptparse.rb
CHANGED
@@ -18,37 +18,37 @@ class TinysshOptparse
|
|
18
18
|
opts.separator ""
|
19
19
|
opts.separator "Specific options:"
|
20
20
|
|
21
|
-
opts.on("-u", "--user [user]",
|
21
|
+
opts.on("-u", "--user [user]",
|
22
22
|
"Specify a user for accessing remote hosts.(default: root)") do |user|
|
23
23
|
options.user = user
|
24
24
|
end
|
25
25
|
|
26
|
-
opts.on("-p", "--port [port]",
|
27
|
-
"Port to connect to on the remote host(default:
|
26
|
+
opts.on("-p", "--port [port]",
|
27
|
+
"Port to connect to on the remote host(default: 22)") do |port|
|
28
28
|
options.port = port
|
29
29
|
end
|
30
30
|
|
31
|
-
opts.on("-t", "--timeout [time]",
|
31
|
+
opts.on("-t", "--timeout [time]",
|
32
32
|
"Set the command timeout to seconds(default: 0)") do |timeout|
|
33
33
|
options.timeout = timeout.to_i
|
34
34
|
end
|
35
35
|
|
36
|
-
opts.on("-l", "--list-file [file]",
|
36
|
+
opts.on("-l", "--list-file [file]",
|
37
37
|
"File containing a list of hosts' IP Address") do |file|
|
38
38
|
options.host_file = file
|
39
39
|
end
|
40
40
|
|
41
|
-
opts.on("-o", "--output-file [file]",
|
41
|
+
opts.on("-o", "--output-file [file]",
|
42
42
|
"Output result to log file") do |output_file|
|
43
43
|
options.output_file = output_file
|
44
44
|
end
|
45
45
|
|
46
|
-
opts.on("-i", "--identity-keys [keys]",
|
46
|
+
opts.on("-i", "--identity-keys [keys]",
|
47
47
|
"identity (private) keys for authentication(default: /root/.ssh/id_rsa)") do |keys|
|
48
48
|
options.keys = keys
|
49
49
|
end
|
50
50
|
|
51
|
-
opts.on("-n", "--number-of-thread [number]",
|
51
|
+
opts.on("-n", "--number-of-thread [number]",
|
52
52
|
"Specify the number of concurrent jobs for each execution") do |num|
|
53
53
|
options.num = num
|
54
54
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tinyssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- William Herry
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
requirements: []
|
64
64
|
|
65
65
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.8.
|
66
|
+
rubygems_version: 1.8.24
|
67
67
|
signing_key:
|
68
68
|
specification_version: 3
|
69
69
|
summary: Tiny SSH
|