Created
April 10, 2020 19:15
-
-
Save halferty/e2bedba20667cb7f07f6bc7439dddc51 to your computer and use it in GitHub Desktop.
End processes matching string
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/env ruby | |
require "io/console" | |
keywords = ARGV.reject { |arg| arg.length < 4 } | |
`ps auxww`.split(/\n/) | |
.reject { |line| line.include?("killify") } | |
.filter { |line| keywords.any? { |k| line.include?(k) } } | |
.map { |line| line.split(/\s+/) } | |
.map { |line| [line[1], line[10..-1].join(" ")] } | |
.each { |line| | |
puts "Kill process #{line[0]}? (y/N) (with CLI \"#{line[1]}\")" | |
if STDIN.getch.downcase === 'y' | |
puts `kill -9 #{line[0]}` | |
end | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment