Skip to content

Instantly share code, notes, and snippets.

@newjam
Created September 14, 2018 11:09
Show Gist options
  • Save newjam/729ca1e7e772d7151130012b05dca7fb to your computer and use it in GitHub Desktop.
Save newjam/729ca1e7e772d7151130012b05dca7fb to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/ssh'
def main
if ARGV.size < 3 then
puts 'usage: <hostname> <username> <password>'
else
hostname = ARGV[0]
username = ARGV[1]
password = ARGV[2]
n = 1000
foo(hostname, username, password)
end
end
def foo(hostname, username, password, n = 500)
Net::SSH.start(hostname, username, password: password) do |ssh|
ssh.open_channel do |channel|
channel.on_close do
puts 'shell closed'
end
channel.on_data do |c, data|
puts data
end
channel.send_channel_request 'shell'
(1..n).each do |i|
channel.send_data "ls -la\n"
end
#puts "exit\n"
channel.send_data "exit\n"
end
ssh.loop
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment