ckennedy2
2/10/2005 8:53:00 PM
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',
:keys=>["C:\SSH\HostKeys"]
) do |session|
shell = session.shell.open
shell.send_data "/home/user/bin/copy_log\n"
shell.exit
sleep 10.0
$stdout.print shell.stdout while shell.stdout?
$stderr.puts "-- stderr: --"
$stderr.print shell.stderr while shell.stderr?
end
# 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
end
#Need to repeat this 7 more times 'somehow' with different server name
do_sshget("server123456")
ERROR:
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in
`initialize':
getaddrinfo: no address associated with hostname. (SocketError)
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in `
open'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:83:in `
initialize'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/services.rb:121:in
`new'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/services.rb:121:in
`register_services'
from
C:/ruby/lib/ruby/site_ruby/1.8/net/ssh/transport/services.rb:115:in
`call'
from
C:/ruby/lib/ruby/gems/1.8/gems/needle-1.2.0/lib/needle/lifecycle/si
ngleton.rb:42:in `call'
from
C:/ruby/lib/ruby/gems/1.8/gems/needle-1.2.0/lib/needle/lifecycle/si
ngleton.rb:40:in `synchronize'
from
C:/ruby/lib/ruby/gems/1.8/gems/needle-1.2.0/lib/needle/lifecycle/si
ngleton.rb:40:in `call'
... 25 levels...
from C:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:47:in `new'
from C:/ruby/lib/ruby/site_ruby/1.8/net/ssh.rb:47:in `start'
from log_get.rb:7:in `do_sshget'
from log_get.rb:27