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.4"
- 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ccsh.rb', line 11 def self.execute! begin = 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] hosts = CCSH::Hosts.new.parser!(filename).filter_by(targets) self.start_cli(hosts, ) rescue Exception => e if not e. == 'exit' CCSH::Utils.debug "Backtrace:\n\t#{e.backtrace.join("\n\t")}\n\n" CCSH::Utils.verbose "Backtrace:\n\t#{e.backtrace.join("\n\t")}\n\n" puts "An error occur and system exit with the following message: " puts " #{e.}" exit! end exit end end |
.start_cli(hosts, options) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ccsh.rb', line 74 def self.start_cli(hosts, ) CCSH::Utils.display_hosts(hosts) if [:show_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 if ((.max_threads == 0) || (.max_threads > hosts.length)) .max_threads = hosts.length end CCSH::Utils.debug "Using #{.max_threads} maximum of threads" hosts.each_slice(.max_threads) do |batch_hosts| threads = [] batch_hosts.each do |host| threads << Thread.new do info = with_info() do host.run command end end end threads.each(&:join) end end end rescue Exception => exception STDERR.puts exception. STDERR.puts raise exception end end end |
.with_info(options) ⇒ 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 |
# File 'lib/ccsh.rb', line 41 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 prompt = ">>> #{cmd.hostname} #{info}" puts prompt STDERR.puts cmd.stderr if cmd.stderr != nil && cmd.stderr != '' puts cmd.stdout if cmd.stdout != nil && cmd.stdout != '' puts if [:output] != nil begin file_handler = File.new([:output], "a+") file_handler.write("#{prompt}\n") file_handler.write("ERROR: #{cmd.stderr}") if cmd.stderr != nil && cmd.stderr != '' file_handler.write("#{cmd.stdout}\n") if cmd.stdout != nil && cmd.stdout != '' rescue Exception => e puts "WARNING: An error occur when trying to write the output to file: #{[:output]}. " puts "WARNING: Thefore, the output is not being stored" puts "WARNING: Error message: #{e.}" end end end |