On 05:55 Fri 11 Feb     , ckennedy2 wrote:
> Hello, I have a question and hope this is the correct area for it. If not
> please feel free to direct me elsewhere. 
> 
> Q:
> I'm looking to implement an SSH based script/utility to connect to 8
> different boxen, execute various commands and retrieve a file. The Perl
> and Ant SSH implementation just don't seem to have what I need. I've
> checked into this Ruby implementation and like it the best. I'm having a
> problem tho, here's the code, based off Jamis' examples. Also the problem
> seem to be when I call my method , @server isn't being recognized by my
> Net:SSH call (getting socket error):
> 
> Code:
> 
> require 'net/ssh'
> 
> 
> def do_sshget (sshserver)
> 
> 
>   @sshserver = sshserver
> 
>   Net::SSH.start( 
>   "@sshserver", 'user', 'passw',
    ^^^^^^^^^^^^
  
The problem is right there. Just use the sshserver variable directly,
like this:

  Net::SSH.start( sshserver, 'user', 'passw',
     :keys=>["C:\\SSH\\HostKeys"] ) 

Also, note that the backslashes are escpaed in the keys
string.

If you want to use string interpolation (where you specify an
expression inside the string and have it evaluated in the string), use
the "#{...}" syntax:

  "#{@sshserver}"

>   # Copy the logs locally, can't find SCP in Ruby,    shelling out to
> Putty's pscp.exe
>   f=IO.popen("pscp -pw pass
> user@"@sshserver":/home/user/log_archive/@sshserver.jar @sshserver.jar")
>   p f.readlines

Can you use SFTP? I'm "kind of" working on an SCP module for Ruby, but
it's hard going (the protocol is not documented at all, so I'm having
to extract it from the source code). In the meantime, there is
a pretty fully-functioning SFTP module for Ruby:

  Net::SFTP.open( @sshserver, 'user', 'passw' ) do |sftp|
    sftp.open_handle (
      "/home/user/log_archive/#{@sshserver}.jar"
    ) do |handle|
      log = sftp.read( handle )
      p log
    end
  end

Hope that helps,

Jamis


-- 
Jamis Buck
jamis_buck / byu.edu
http://jamis.jamisbuck.org
------------------------------
"I am Victor of Borge. You will be assimil-nine-ed."