Thursday, October 16, 2008

Ruby for dummies - Nine Steps for NetBeans and Net::SSH

-----------
Hello World
-----------
The system cannot find the path specified
total 32
drwx------ 2 root root 16384 Mar 28 2008 lost+found
drwxrwx--- 3 oracle oracle 4096 May 8 02:29 oracle
drwxr-xr-x 7 test test 4096 Mar 28 2008 test
-------------
Goodbye World
-------------



Above is the final product after some frustration with JRuby and Netbeans detailed in previous postings. I've been trying to follow simple Ruby SSH tutorials with little or no luck.

The primary cause is due to net/ssh and Ruby's reliance on the PuTTY pageant service when running in Windows, explained --> here (the dl/import issue).

For me, the message "The system cannot find the path specified" threw a flag that things were not working when in fact they actually were.

So in lieu of my efforts and time spent, I'm writing a tutorial for a JRuby beginner trying to obtain the same results.

  1. Install Netbeans 6.5 (6.1 should work also)


  2. If its not already install the two required NetBeans plugins: "Ruby and Rails" and "JRuby and Rails" through the plugins interface.




  3. Install the two required JRuby "gems": net-ssh (>2.0.4) and jruby-openssl (>0.3)






  4. Create a new JRuby Application through
    File --> New Project --> Ruby --> Ruby Application


  5. Overwrite
    C:\Program Files\NetBeans 6.5 Beta\ruby2\jruby-1.1.3\lib\ruby\gems\1.8\gems\net-ssh-2.0.4\lib\net\ssh\authentication\pageant.rb

    with this version: --> pageant.rb

  6. Overwrite
    C:\Program Files\NetBeans 6.5 Beta\ruby2\jruby-1.1.3\lib\ruby\gems\1.8\gems\net-ssh-2.0.4\lib\net\ssh\known_hosts.rb

    with this version: --> known_hosts.rb

  7. Copy/Paste the following code:
    require 'rubygems'
    require 'net/ssh'

    puts "-----------"
    puts "Hello World"
    puts "-----------"


    Net::SSH.start('192.168.1.7', 'test', :password => "passw0rd") do |ssh|
    # capture all stderr and stdout output from a remote process
    #output = ssh.exec!("talia")
    # capture only stdout matching a particular pattern
    stdout = ""
    ssh.exec!("ls -l /home") do |channel, stream, data|
    stdout << stream ="=">

  8. Modify "main.rb" code in NetBeans so that it points to a device on your networking running ssh.


  9. Run your program


  10. Hopefully you had success!? :)
-Tres

3 comments:

Angel said...
This comment has been removed by the author.
Angel said...

This small change of mine in net-ssh works on my machine. Can you let me know if it works for you too?

http://github.com/angelic/net-ssh/commit/dd4adaa368583dbeb6cb10038b6961a50354e5c6

Angel N. Sciortino

FatButtLarry said...

By looking at it, it looks like it should. Cheers. Hopefully this will be changed in the net-ssh to something similar moving forward!

-Tres

"This small change of mine in net-ssh works on my machine. Can you let me know if it works for you too?

http://github.com/angelic/net-ssh/commit/dd4adaa368583dbeb6cb10038b6961a50354e5c6

-Angel"