Module: CCSH
- Defined in:
- lib/ccsh.rb,
lib/ccsh/ssh.rb,
lib/ccsh/host.rb,
lib/ccsh/hosts.rb,
lib/ccsh/utils.rb,
lib/ccsh/options.rb,
lib/ccsh/version.rb
Defined Under Namespace
Modules: Options, SSH, Utils Classes: Host, Hosts
Constant Summary collapse
- VERSION =
ccsh relased version
"0.0.3"
- BUILD_NUMBER =
the git commit tag number that generate this build
"dev-#{VERSION}"
Class Method Summary collapse
Class Method Details
.execute! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ccsh.rb', line 11 def self.execute! = CCSH::Options. ARGV ENV['CCSH_DEBUG'] = "true" if [:debug] ENV['CCSH_VERBOSE'] = "true" if [:verbose] raise "You must to specified a hostname or group" if [:targets].empty? filename = [:hosts] targets = [:targets] self.start_cli CCSH::Hosts.new.parser!(filename).filter_by(targets) end |
.start_cli(hosts) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ccsh.rb', line 41 def self.start_cli(hosts) quit = false loop do begin CCSH::Utils.handle_signals printf "ccsh> " command = STDIN.gets.chomp if command != '' CCSH::Utils.exit_console 0 if command == 'quit' CCSH::Utils.exit_console 0 if command == 'exit' if command == 'clear' CCSH::Utils.clear_console elsif command == 'reset' CCSH::Utils.reset_console else threads = [] hosts.each do |host| threads << Thread.new do with_info do host.run command end end end threads.each(&:join) end end rescue Exception => exception STDERR.puts exception. STDERR.puts raise exception end end end |
.with_info ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ccsh.rb', line 25 def self.with_info cmd_start = Time.now cmd = yield cmd_end = Time.now info = { 'rc' => cmd.return_code, 'time' => cmd_end - cmd_start, }.inspect puts ">>> #{cmd.hostname} #{info}" STDERR.puts cmd.stderr if cmd.stderr != nil && cmd.stderr != '' puts cmd.stdout if cmd.stdout != nil && cmd.stdout != '' puts end |