Hi,
Can someone give me some advice on how to reliably check that a server
is alive and accepts ssh login? Have tried ping but that opens a small
window that ssh login is still not available.
Thanks.
Hi,
Can someone give me some advice on how to reliably check that a server
is alive and accepts ssh login? Have tried ping but that opens a small
window that ssh login is still not available.
Thanks.
On Aug 26, 2011, at 11:59 AM, Rick T. wrote:
Hi,
Can someone give me some advice on how to reliably check that a server
is alive and accepts ssh login? Have tried ping but that opens a small
window that ssh login is still not available.
With 1.9.2 you can say -
require ‘socket’
s = TCPSocket.open(‘myfavoritehost.com’, 22)
s.gets(3).eql? “SSH”
Dan N.
On Sat, Aug 27, 2011 at 02:03:12AM +0900, Dan N. wrote:
require ‘socket’
s = TCPSocket.open(‘myfavoritehost.com’, 22)s.gets(3).eql? “SSH”
Using the following in IRB:
irb(main):008:0> s = TCPSocket.open(‘localhost’, 22)
=> #TCPSocket:0x7f5f1cb95ff0
irb(main):009:0> s.gets.eql? “SSH”
=> false
Retrying with s.gets(3).eql? “SSH” theres:
irb(main):011:0> s.gets(3).eql? “SSH”
TypeError: can’t convert Fixnum into String
from (irb):11:in `gets’
from (irb):11
from :0
Instead try:
s.gets.include? “SSH”
though I’d suspect that an established connection on port 22 should be
sufficient to say it’s enabled and working, and just use the response to
check what versions (SSH1 or SSH2) are supported.
Being able to pass #gets a length limit parameter is new in ruby 1.9
The key point is that an active SSH port will spontaneously spit out
“SSH”
followed by a bunch of other stuff when socket 22 is opened.
There are any number of techniques to collect the string and make the
appropriate comparison. Given that TCPSocket has a whopping 190
different
instance methods in 1.9.2, there are a great many ways to skin this
particular cat.
PS - From the shell you might also try “telnet myfavoritehost.com 22”
to get an idea of what’s going on.
Dan N.
Thanks a lot.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs