On Wed, Oct 26, 2011 at 2:35 PM, KING SABRI <king.sabri / gmail.com> wrote:
> Thanks Brian,,
> "Net::SSH::Telnet" is has an advantage which it's keeping the session
> open until finish all commands not like "Net::SSH" which is create a
> session for each command/communication.
>
> However, it doenst solve my issue
>
> ------------------------------------------------------------
> require 'net/ssh/telnet'
>
> =A0host =3D "127.0.0.1"
> =A0port =3D 15000 =A0 =A0# SSH port
> =A0user =3D 'userName' =A0# username
> =A0pass =3D "password" =A0# password
>
>
> s =3D Net::SSH::Telnet.new("Host" =3D> host, "Username" =3D> user, "Passw=
ord"
> =3D> pass)
>
> =A0puts s.cmd("pwd")
> =A0puts s.cmd "sudo passwd userName"
> ------------------------------------------------------------
>
> that's my code :(

Not sure whether that works but you could use "expect" to match and
react on what the remote side says.

require 'expect'

# example with file
File.open "x" do |io|

  io.expect /^prompt/ do |line|
    puts "Got #{line}"
    io.puts "exit"
  end
end

Kind regards

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/