Created
July 26, 2009 01:27
-
-
Save jamesgolick/155395 to your computer and use it in GitHub Desktop.
This file contains 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
Net::SSH::Simple.new do |s| | |
s.servers "server1" | |
exit_code = s.run "ls -la" do |cmd| | |
cmd.on_stdout do |stdout| | |
end | |
cmd.on_stderr do |stderr| | |
end | |
end | |
end |
This file contains 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
class DataHandler | |
def on_stdout(stdout) | |
end | |
def on_stderr(stderr) | |
end | |
end | |
Net::SSH::Simple.new do |s| | |
s.servers "server1" | |
exit_code = s.run "ls -la", DataHandler.new | |
end |
This file contains 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
class DataHandler | |
def on_stdout(stdout) | |
end | |
def on_stderr(stderr) | |
end | |
end | |
ssh = Net::SSH::Simple.new("server1", :data_handler => DataHandler.new) | |
exit_code = ssh.run "ls -la" | |
begin | |
ssh.run! "thiscommandclearlydoesn'texist" | |
rescue Net::SSH::Simple::CommandFailedError => e | |
exit_code = e.exit_code | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment