Class: FissherBase
- Inherits:
-
Object
- Object
- FissherBase
- Defined in:
- lib/fissher_base.rb
Overview
Main class. This one does all the dirty work.
Instance Method Summary collapse
-
#go_time ⇒ Object
The guts of the app.
Instance Method Details
#go_time ⇒ Object
The guts of the app. This handles putting everything together and running the commands via Net::SSH::Multi.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fissher_base.rb', line 12 def go_time opts = FissherConf.handle_opts unless !opts.nil? abort "No hosts specified! Please use -H or -G!\n" unless !opts[:hostlist].nil? Net::SSH::Multi.start(:concurrent_connections => opts[:concurrency], :on_error => :warn) do |session| if opts[:gateway] session.via opts[:gateway], opts[:user], :password => opts[:password] end # Create our connection list opts[:hostlist].each do |host| session.use host, :user => opts[:user], :password => opts[:password] end if opts[:command] =~ /^sudo/ if opts[:password].nil? p = FissherConf::Misc.new opts[:password] = p.getpass end # Get a PTY and exec command on servers session.open_channel do |ch| ch.request_pty do |c, success| raise "could not request pty" unless success ch.exec opts[:command] ch.on_data do |c_, data| if data =~ /\[sudo\]/ ch.send_data(opts[:password] + "\n") else puts "[#{ch[:host]}]: #{data}" unless data =~ /^\n$|^\s*$/ end end end end else # Sudo isn't needed. We don't need a PTY. session.exec(opts[:command]) end # go time... for real. session.loop end end |