This is what I got so far. This works great, the problem being I can't input a password for the ssh login, I need to have shared ssh keys in order for this to work:
def ssh_conn(user, host, &block)
begin
ping_output = []
timeout(20) do
ping_output = IO.popen("ssh #{user}@#{host} 'echo \"success\"'", "w+")
end
ping = ping_output.readlines.join[/success/] ? true : false
rescue Timeout::Error
ping = false
rescue
ping = false
end
ping_output.close
if block_given? && ping
yield
end
return ping
end
The question here is: How can I do something similar to this, but with password input through the arguments passed to the method? Preferably using ruby native Classes/Methods without installing any "external" gems.