Created
April 13, 2010 07:50
-
-
Save mhansen/364404 to your computer and use it in GitHub Desktop.
Quick script, pings a host, if two pings time out in a row, run 'mtr' to pinpoint where the loss is occurring
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
puts 'Usage: ruby ping.rb IP_TO_MONITOR' unless ARGV[0] | |
exit unless ARGV[0] | |
ip = ARGV[0] | |
while true | |
ping = IO.popen('ping -q -c2 '+ip) | |
ping_str = ping.readlines | |
ping.close | |
match = ping_str.join.match(/(\d) received/) | |
num_received = match ? match[1] : '0' | |
if num_received == '0' | |
puts Time.now.to_s | |
mtr = IO.popen('mtr --report -c 10 '+ip) | |
puts mtr.readlines | |
mtr.close | |
puts '' | |
STDOUT.flush | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment