2

I am building a raspberry-pi clients manager, where those clients are connected to a server through SSH reverse tunnels. I am using for this the Sinatra framework and the net-ssh library. For single commands this is obvious, I used server-side events where I send the commands to a given url. At That action, the command is pushed to a queue, and get executed asynchronously, then the results get pushed to the event-stream connection whenever data is available, here is the pseudo code of the command runner:

 require 'net/ssh'
 # start a separate thread avoid blocking the main thread of the server.
 Thread.start do
      sess = Net::SSH.start(HOST, USER, :password => 'pass', :port => 'port')
      # once a command is pushed to the queue on the dedecated sinatra action
      # the command get executed, once the execution ends this will start listening
      # again
    loop{
      sess.exec! (queue.pop()) do|ch, stream, data|
      #this is the server-sent events stream, here the data is pushed to the client 
      #EventSource 
      stream_event_connection << data
      end
    }
 end

for single commands this is ok, for example a command like 'ls /root'. But what I need is to open a live terminal(Interective shell), where the user enters commands and gets results like if its on a real ssh terminal.I though migh be opening a pty on the remote Respberry-PI client, and by using the expect library, this will be possible. For requesting a pty their is the Net::SSH::Connection::Channel#request_pty method, but I cannot find any example on how to use it. any ideas?

Nafaa Boutefer
  • 2,169
  • 19
  • 26

1 Answers1

0

I believe what you're looking for can be done like:

shell = sess.shell.open(:pty => true)
...
shell.exec! queue.pop ...

Hope that helps

13m5
  • 139
  • 2