Skip to content

Instantly share code, notes, and snippets.

@jjam3774
Created March 21, 2016 01:17
Show Gist options
  • Save jjam3774/12bfbbd7dbff167aedd0 to your computer and use it in GitHub Desktop.
Save jjam3774/12bfbbd7dbff167aedd0 to your computer and use it in GitHub Desktop.
Simple net-ssh example
#!/usr/bin/ruby
require 'rubygems'
require 'net/ssh'
host = "192.168.1.120"
user = "vagrant"
pass = "vagrant"
commands = %Q{
hostname
uptime
ifconfig
}
###
# Simple Example of net-ssh gem
###
Net::SSH.start( host , user, :password => pass, :paranoid => false ){|ssh|
begin
result = ssh.exec!(commands)
rescue Net::SSH::HostKeyMismatch => e
puts "remembering new key: #{e.fingerprint}"
e.remember_host!
retry
end
puts result.upcase
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment