miércoles, 9 de mayo de 2012

Wiki Contributions - Week 14

For this week, what I wanted to do is to issue some commands from a web page in ruby on rails, to do some things through ssh on a virtual computer. I managed to do this, but not as I expected, because I can't actually get to understand how ruby on rails works, and the only thing I could do is put my code that runs an ls command through ssh, somewhere between other operations of the web application. The code runs, and effectively does a ssh, but obviously I wanted the web application to ask for a command to run, which I couldn't done.

Anyway the specific code that I added to a ruby on rails application is the following:

#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'

HOST = '192.168.1.75'
USER = 'user'
PASS = 'its'

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

The code uses the Net::SSH gem, which I explained previously and there is an entry about it on the wiki.
This is not exactly the code itself, because I had to adapt it to the ruby on rails application, which works pretty weird and the only thing I could do to print the output data from the remote ls instruction, was to use some kind of html function that ruby on rails added to the code.



I updated the wiki with this and other examples I found using Net::SSH.
Nominaciones:


Alex and Victor

1 comentario: