From: "Darryl L. Pierce" Date: 2011-08-27T02:16:33+09:00 Subject: Re: ssh login to a host --pf9I7BMVVzbSWLtt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Aug 27, 2011 at 02:03:12AM +0900, Dan Nachbar wrote: >=20 > On Aug 26, 2011, at 11:59 AM, Rick Tan wrote: >=20 > > Hi, > >=20 > > 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. >=20 > With 1.9.2 you can say - >=20 > require 'socket' > s =3D TCPSocket.open('myfavoritehost.com', 22) >=20 > s.gets(3).eql? "SSH" Using the following in IRB: irb(main):008:0> s =3D TCPSocket.open('localhost', 22) =3D> # irb(main):009:0> s.gets.eql? "SSH" =3D> 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. --=20 Darryl L. Pierce http://mcpierce.multiply.com/ "What do you care what people think, Mr. Feynman?" --pf9I7BMVVzbSWLtt Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iEYEARECAAYFAk5X1O0ACgkQtddqM0QFuLLsSACgs3j1jB3e8TgECWwYo0p0/Cn+ +MMAnjCTe1Bnc3jnCfsiGe5lwin0zTuL =s0mN -----END PGP SIGNATURE----- --pf9I7BMVVzbSWLtt--