I am trying to create a web app that allows me to invoke a command on
another server via an SSH session. I am currently doing this as
- User is presented with a form to enter server, command, username and
- User clicks “Run” and form is submitted to the “run_command” action.
- The “run_command” action initiates an SSH session using net-ssh and
registers callbacks with the SSH session to append any command output to
the web session[:command_output]. Thus, session[:command_output] grows
until all results (stdout and stderr) are accumulated.
- The “run_command” redirects to the results page which then renders
the web session[:command_output] which is viewed by the user.
This is working fine, but what I really want to do is alter step 3 so
that the SSH session accumulates the results but the results page is
rendered before the SSH session is complete. Then in step 4 I could use
AJAX to periodically update the command output results as they come in
instead of waiting for them all to come in before displaying them.
In order to do this it seems I would need threading and that introduces
complexities and prefer to not deal with.
Another possibility I thought of was to somehow have the results page be
the one that makes an AJAX call to the “run_command” action that will
initiate the SSH session, and have the SSH session callbacks send the
data to the browser realtime instead of appending to the web session
variable. I’ve done something similar in Python with Twisted and
Nevow/LivePage before, but am unsure how to do so with Rails.
Does anyone have any thoughts or advice on how I might solve this