Class: Miab
- Inherits:
-
Object
- Object
- Miab
- Defined in:
- lib/miab.rb
Defined Under Namespace
Classes: Session
Instance Method Summary collapse
-
#cast ⇒ Object
cast out the thing and hope for the best.
-
#initialize(scroll, domain: nil, target: nil, pwlist: {}, password: nil, user: nil, debug: false) ⇒ Miab
constructor
A new instance of Miab.
Constructor Details
#initialize(scroll, domain: nil, target: nil, pwlist: {}, password: nil, user: nil, debug: false) ⇒ Miab
Returns a new instance of Miab.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/miab.rb', line 154 def initialize(scroll, domain: nil, target: nil, pwlist: {}, password: nil, user: nil, debug: false) @results = {} @scroll, @debug = scroll, debug @nodes = if target then target = [target] if target.is_a? String target.inject({}) do |r,x| host = domain ? x + '.' + domain : x passwd = pwlist[x] || password userhost = user ? user + '@' + host : host r.merge({userhost => passwd}) end else {} end end |
Instance Method Details
#cast ⇒ Object
cast out the thing and hope for the best
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/miab.rb', line 179 def cast() if @nodes.any? then threads = [] @nodes.each do |raw_host, password| host, user = raw_host.split(/@/,2).reverse @results[host] = {} threads << Thread.new do begin puts ('host: ' + host.inspect).debug if @debug ssh = Net::SSH.start( host, user, password: password) @results[host] = Session.new(host, ssh, debug: @debug).exec @scroll ssh.close puts (host + ' result: ' + @results[host].inspect).debug if @debug rescue @results[host] = nil end end end threads.each(&:join) else if @scroll then host = `hostname`.chomp @results[host] = Session.new(host, debug: @debug).exec(@scroll) end end @scroll = nil @results end |