Created
April 24, 2012 04:05
-
-
Save hh/2476311 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'em-winrm' # should look at this, it works in parallel | |
require 'winrm' | |
require 'highline' | |
HOST=ARGV[0] | |
COMMAND=ARGV[1] # 'hostname' | |
env = ENV['OPSCODE_ENV'] || 'prod' | |
case env | |
when /qa/ | |
PASSWORD='BAR' | |
when /prod/ | |
PASSWORD='FOO' | |
end | |
def h | |
@highline ||= HighLine.new | |
end | |
def print_data(host, data, color = :cyan) | |
if data =~ /\n/ | |
data.split(/\n/).each { |d| print_data(host, d, color) } | |
else | |
puts "#{h.color(host, color)} #{data.chomp}" | |
end | |
end | |
begin | |
print_data HOST, COMMAND, :blue | |
winrm = WinRM::WinRMWebService.new( "http://#{HOST}:5985/wsman", | |
:plaintext, | |
:user => "Administrator", :pass => PASSWORD, | |
:basic_auth_only => true) | |
winrm.cmd(COMMAND) do |stdout, stderr| | |
print_data(HOST, stdout) if stdout | |
print_data(HOST, stderr, :red) if stderr | |
end | |
rescue | |
print_data HOST, "A low level error occured", :red | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment