Guillaume Caillé Guillaume Caillé - 1 year ago 158
Ruby Question

Ruby on rails - cannot load such file -- net/ssh

I've been struggling on this for a few days now..

When I try to call a method in a helper from a view to do ssh, it throws that error.

"This error occurred while loading the following files: net/ssh"

But when I copy the code into a
file and execute it from prompt
ruby test.rb
it connects flawlessly.

What could be the problem ? I tried on another computer and same result.

Thank you very much this is like the last step before I can complete my project!



module ApplicationHelper
def title(value)
unless value.nil?
@title = "#{value} | Eucc"
def execute
require 'rubygems'
require 'net/ssh'
@hostname = "smtlmon02"
@username = "gcaille"
@password = "qaz1234"
@cmd = "ls -al"
@cmd2 = "sudo su - -c 'ls;date'"

ssh = Net::SSH.start(@hostname, @username, :password => @password)
res = ssh.exec!(@cmd)
res2 = ssh.exec!(@cmd2)

ssh.close"output.txt", 'w') {|file| file.write(res2)}

Answer Source

You just need to add it to Gemfile like this:

gem 'net-ssh'

and run bundle install after that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download