Skip to content

Instantly share code, notes, and snippets.

@Whoops
Created September 8, 2010 17:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Whoops/570440 to your computer and use it in GitHub Desktop.
require 'net/ssh'
print "Enter host: "
host=gets.chomp
print "Enter username: "
user=gets.chomp
print "Enter password: "
password=gets.chomp
Net::SSH.start(host, user, :password => password) do |ssh|
channel = ssh.open_channel do |ch|
ch.exec "iptables -L" do |ch, success|
raise "error running command" unless success
#stdout
ch.on_data do |c, data|
puts data
end
#stderr
ch.on_extended_data do |c, type, data|
puts data
end
ch.on_close { puts "work complete!" }
end
channel.wait
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment