Please help with NET::SSH

J

Jean-eric Godard

Hello ,
I use the NET::SSH gem, and I have some trouble using it, I can't send
successive command.
Per example when I type the commands :
"ls" followed by "cd desktop" and then "ls" again.
the second time I send "ls", return me the exact same list as the first
"ls" send the "cd desktop" command is ignored.
net::ssh act like if it open a new terminal for each command send.

Here the code I use:

require 'rubygems'
require 'net/ssh'


HOST = '192.168.0.3'
USER = 'utilisateur'
PASS = 'motdepasse'

Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|
ssh.exec('ls')
ssh.exec('cd Desktop')
ssh.exec('ls')
end

I use NET::SSH version (2.0.23) on ruby 1.9.2p0.
Can someone please send me the code allowing me to send these two
simples commands in series to the terminal.
As it seems the above code send these commands in parallels.

Thanks very much.
 
D

Daniel Pittman

I use the NET::SSH gem, and I have some trouble using it, I can't send
successive command.
Per example when I type the commands :
"ls" followed by "cd desktop" and then "ls" again.
the second time =C2=A0I send "ls", return me the exact same list as the f= irst
"ls" send the "cd desktop" command is ignored.
net::ssh act like if it open a new terminal for each command send.

It is: the 'exec' operation opens a new channel to the server, runs
the given command, then closes it.

To do what you want there you would need to exec /bin/sh, then drive
that with send_input.

Regards,
Daniel
--=20
=E2=9C=A3 Daniel Pittman =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=E2=9C=89=
(e-mail address removed) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=E2=98=8E +61=
401 155 707
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =E2=99=BD made with 100 pe=
rcent post-consumer electrons
 
J

Jean-eric Godard

Many thanks for your reply.

Unfortunately I have little computer programming knowledge.

I try to do what you write and send the follwing commands:

Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|

ssh.exec('/bin/sh')
ssh.exec('cd Desktop')
ssh.exec('ls')

end

and other syntax like this

Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|

ssh.exec('exec /bin/sh')
ssh.exec('cd Desktop')
ssh.exec('ls')

end

but nothing works

please how can I send these magic commands.

Best regards
 
B

Brian Candler

Jean-eric Godard wrote in post #969505:
Many thanks for your reply.

Unfortunately I have little computer programming knowledge.

Try using Net::SSH::Telnet gem instead. This wraps Net::SSH with a
simple send/expect API just like Net::Telnet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top