Created
March 21, 2016 01:17
-
-
Save jjam3774/12bfbbd7dbff167aedd0 to your computer and use it in GitHub Desktop.
Simple net-ssh example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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