Skip to content

Instantly share code, notes, and snippets.

@christiankakesa
Last active November 17, 2016 10:29
Show Gist options
  • Save christiankakesa/a6dfe8b45c4d888504231b588d582924 to your computer and use it in GitHub Desktop.
Save christiankakesa/a6dfe8b45c4d888504231b588d582924 to your computer and use it in GitHub Desktop.
Ruby Net-SSH tests (net-ssh '>= 2.9.2')
require 'logger'
require 'net/ssh'
require 'stud/interval'
@log = Logger.new(STDOUT).tap { STDOUT.sync = true }
@ssh_session = Net::SSH.start('localhost', 'christian', password: 'xxx')
@interruptible = false
trap('SIGINT') { @interruptible = true }
until @interruptible
['ls -lrtp /',
'cat /etc/hosts',
'cat /proc/cpuinfo',
'cat /proc/meminfo',
'cat /proc/loadavg',
'cat /proc/vmstat',
'cat /proc/diskstats',
'cat /proc/net/dev',
'cat /proc/net/wireless',
'cat /proc/mounts',
'cat /proc/crypto',
'cat /proc/sysvipc/shm'][0..2].each do |cmd|
@ssh_session.exec(cmd) do |ch, stream, data|
next unless stream == :stdout # ignore :stderr
@log.info "[SERVER:'#{ch.connection.host}' - CMD:'#{cmd}'] => #{data[0..[20, data.index(/$/) - 1].min]}..."
end
end
@ssh_session.loop
@log.info(String.new('=') * 80)
Stud.stoppable_sleep(10) { @interruptible }
end
@ssh_session.close
@log.info 'ALT!!!'
exit 0
require 'logger'
require 'net/ssh'
require 'stud/interval'
@log = Logger.new(STDOUT).tap { STDOUT.sync = true }
@ssh_session = Net::SSH.start('localhost', 'christian', password: 'xxx')
@interruptible = false
trap('SIGINT') { @interruptible = true }
until @interruptible
['ls -lrtp /',
'cat /etc/hosts',
'cat /proc/cpuinfo',
'cat /proc/meminfo',
'cat /proc/loadavg',
'cat /proc/vmstat',
'cat /proc/diskstats',
'cat /proc/net/dev',
'cat /proc/net/wireless',
'cat /proc/mounts',
'cat /proc/crypto',
'cat /proc/sysvipc/shm'].each do |cmd|
@ssh_session.exec(cmd) do |ch, stream, data|
next unless stream == :stdout # ignore :stderr
@log.info "[SERVER:'#{ch.connection.host}' - CMD:'#{cmd}'] => #{data[0..[20, data.index(/$/) - 1].min]}..."
end
end
@ssh_session.loop
@log.info(String.new('=') * 80)
Stud.stoppable_sleep(10) { @interruptible }
end
@ssh_session.close
@log.info 'ALT!!!'
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment