Last active
November 16, 2018 20:08
-
-
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
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 '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