From: Aaron Samuel Date: 2012-06-30T12:47:10+09:00 Subject: Re: Ruby pty and expect --20cf302ef7ced6f37f04c3a8579a Content-Type: text/plain; charset=UTF-8 I agree with the regex comment and also I have had an easier time / better luck using net-ssh for these type of actions. On Fri, Jun 29, 2012 at 8:10 PM, ZipiZap zap wrote: > Also if any time later you need more from ruby+ssh, have a look at gem > net-ssh > > https://github.com/net-ssh/net-ssh > > Cheers > > > On 29 June 2012 21:10, Tim L. wrote: > >> That was it. thanks a million >> >> PTY.spawn("ssh -o StrictHostKeyChecking=no user@#{address}") do |reader, >> writer, pid| >> reader.expect(/Password/) >> writer.puts("my_password") >> reader.expect(/\$|Password/) do |a, b| >> if a.match(/\$/) >> writer.puts("ifconfig") >> reader.expect(/\$/) >> writer.puts("exit") >> reader.expect(/\$/) >> else >> Process.kill(9, pid) >> end >> >> >> end >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > --20cf302ef7ced6f37f04c3a8579a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I agree with the regex comment and also I have had an easier time / better = luck using net-ssh for these type of actions.



On Fri, Jun 29, 2012 at 8:10 PM, ZipiZap= zap <zipizap123@gmail.com> wrote:
Also if any time later you need more from ruby+ssh, have a look at gem net-= ssh

https://github.com/net-ssh/net-ssh

Cheers


On 29 June 2012 21:10, Tim L. <lists@ruby-forum.com> wrot= e:
That was it. =C2=A0thanks a million

PTY.spawn("ssh -o StrictHostKeyChecking=3Dno user@#{address}") do= |reader,
writer, pid|
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0reader= .expect(/Password/)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0writer.puts(= "my_password")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0reader.expec= t(/\$|Password/) do |a, b|
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if a.= match(/\$/)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0writer.puts("ifconfig")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0reader.expect(/\$/)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0writer.puts("exit")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0reader.expect(/\$/)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0Process.kill(9, pid)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0end

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0end



--20cf302ef7ced6f37f04c3a8579a--