Created
August 6, 2012 18:23
-
-
Save kgrz/3277327 to your computer and use it in GitHub Desktop.
Using Net::SSH gem to kill a process in a remote server. Partial answer to SO question #11832211
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
| If you want to use the net/ssh gem to kill the process: | |
| require 'net/ssh' | |
| Net::SSH.start('host', 'user', :password => "password") do |ssh| | |
| ssh.exec "ps -ax | grep ruby" do |ch, success| | |
| ch.on_data do |c, data| | |
| # Too lazy to write the entire code | |
| # The "data" object has the output that gets printed out to stdout | |
| # when the command `ps -ax | grep ruby` gets executed. | |
| # So you need to split the lines..something like data.split("\n") | |
| # That gives you an array of all processes that are running ruby | |
| # Get the process id into :process_id by regex of somesort and kill it by | |
| c.exec "kill -9 :process_id" # using c here. Need to check this if `c` can be used. | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment