Skip to content

Instantly share code, notes, and snippets.

@jjam3774
Last active November 16, 2018 20:08
Show Gist options
  • Save jjam3774/1089f4d18b1a81698f28 to your computer and use it in GitHub Desktop.
Save jjam3774/1089f4d18b1a81698f28 to your computer and use it in GitHub Desktop.
A general purpose script that allows me to automate calls to remote systems
#!/usr/bin/ruby
require 'expect'
require 'pty'
commands = %Q(
/etc/init.d/check_rep status
)
File.foreach('hosts'){|host|
puts host.strip
PTY.spawn("ssh -i nso.key #{host}"){|o,i,p|
#o.sync = true
#i.sync = true
$expect_verbose = true # shows actions on screen
if o.expect("#")
i.puts("#{commands}")
o.expect(/[#$]/)
i.puts('exit')
end
begin
o.each_line{|k|
puts k
}
rescue Errno::EIO
ensure
Process.wait p
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment