Shell in old versions of NetSSH

In older versions of net-ssh there used to be a shell function that allowed
you to open up a shell on the remote host and issue commands. At some point
this was removed

Presently it is possible to issue commands with something like

ssh = Net::SSH.start(...)
ssh.exec!(some command or other)

The problem is each exec! call opens a new shell on each call so it is not
possible to retain your state on the remote machine. The following is not
possible

ssh.exec!('tar -zxf fred.tgz')
ssh.exec!('cd fred')
ssh.exec!('./configure') <- This fails

Being a new shell means that it starts in ~ and not ~/fred. There are ways
around this - massive single line commands like

ssh.exec!('(tar -zxf fred.tgz ; cd fred ; ./configure ; ... ')

Am I missing something or is there another way to open up a shell over ssh?

Hi Peter,

How about this gem? I haven't tried it but found it with a quick google
search, seems promising. But it also hasn't been updated in a while, I have
no idea how compatible it is with the latest versions of Ruby and Net::SSH.

···

On Mon, Nov 27, 2017 at 2:03 AM Peter Hickman < peterhickman386@googlemail.com> wrote:

In older versions of net-ssh there used to be a shell function that
allowed you to open up a shell on the remote host and issue commands. At
some point this was removed

Presently it is possible to issue commands with something like

ssh = Net::SSH.start(...)
ssh.exec!(some command or other)

The problem is each exec! call opens a new shell on each call so it is not
possible to retain your state on the remote machine. The following is not
possible

ssh.exec!('tar -zxf fred.tgz')
ssh.exec!('cd fred')
ssh.exec!('./configure') <- This fails

Being a new shell means that it starts in ~ and not ~/fred. There are ways
around this - massive single line commands like

ssh.exec!('(tar -zxf fred.tgz ; cd fred ; ./configure ; ... ')

Am I missing something or is there another way to open up a shell over ssh?

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--

- Raj

Problem is that net-ssh-shell is tied to net-ssh at version ~> 2.1.0
whereas net-ssh is around 4.1.0​

Agreed it's old. Maybe you could fix it up?

···

On Tue, Nov 28, 2017 at 7:22 AM Peter Hickman < peterhickman386@googlemail.com> wrote:

Problem is that net-ssh-shell is tied to net-ssh at version ~> 2.1.0
whereas net-ssh is around 4.1.0​

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--

- Raj

Had a quick poke and it was fighting me all the way. Maybe when I have some
more time

···

On 28 November 2017 at 19:48, Raj Sahae <rajsahae@gmail.com> wrote:

Agreed it's old. Maybe you could fix it up?

On Tue, Nov 28, 2017 at 7:22 AM Peter Hickman <peterhickman386@googlemail. > > wrote:

Problem is that net-ssh-shell is tied to net-ssh at version ~> 2.1.0
whereas net-ssh is around 4.1.0​

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

--

- Raj

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;

You can issue commands via ssh like in the snippet below,
if you have alredy set up authorized_keys.
If not you, could try "expect".

I send tou this snippet, I can't elaborate much more because...
I am just a beginner in Ruby;P

It should retain state because you are sending commands always
to the same process. I did not try, I am in a hurry, and tomorrow
I will not be at the keyboard.

···

------------------------------------------------
require 'pty'
fr, fw, sshPid = PTY.spawn("ssh p@foobar.com")
fw.sync = true;
fw.puts("touch f1.test")
fw.puts("touch f2.test")
------------------------------------------------

Hope it helps,

Bye
Nicola Mingotti

On 27/11/2017 11:03, Peter Hickman wrote:

In older versions of net-ssh there used to be a shell function that allowed you to open up a shell on the remote host and issue commands. At some point this was removed

Presently it is possible to issue commands with something like

ssh = Net::SSH.start(...)
ssh.exec!(some command or other)

The problem is each exec! call opens a new shell on each call so it is not possible to retain your state on the remote machine. The following is not possible

ssh.exec!('tar -zxf fred.tgz')
ssh.exec!('cd fred')
ssh.exec!('./configure') <- This fails

Being a new shell means that it starts in ~ and not ~/fred. There are ways around this - massive single line commands like

ssh.exec!('(tar -zxf fred.tgz ; cd fred ; ./configure ; ... ')

Am I missing something or is there another way to open up a shell over ssh?

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk&gt;