-
-
Save anonymous/5833cc8d4d0e58354590 to your computer and use it in GitHub Desktop.
This file contains 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 'pry' | |
servers = { | |
"MAIN_SERVER_1" => "192.168.1.1" # <<-- SERVER IP HERE | |
} | |
user = 'user' | |
command = "tail -F /path/to/log.log | grep 'text here'" | |
thrs = [] | |
servers.each do |server, ip| | |
thrs << Thread.new do | |
puts "Starting Monitor for #{server} @ #{ip}" | |
call = "ssh #{user}@#{ip} #{command}" | |
puts "Making following ssh call: #{call}" | |
# This seems to output to STDOUT | |
# Comment this out to test the IO capture block below | |
system(call) | |
# My attempt to wrap this call in a popen call and handle the IO stream with select | |
IO.popen(call) do |stream| | |
while true | |
r, w, e = IO.select([stream], [], [], 1) | |
puts "Select fired / timed out" | |
# I would expect r (the readable IO array) to have data since stdout has data? | |
# But it always ends up returning nil | |
p r | |
unless r.nil? | |
puts r.first.gets | |
end | |
# If you enable this line, it will drop into the pry shell | |
# Oddly, keystrokes seem to be interruped while in this mode... | |
# But more interestingly, if I perform a stream.gets I see the line return...? | |
# binding.pry | |
end | |
end | |
end | |
end | |
thrs.each { |thr| thr.join } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment