Created
July 28, 2011 15:54
-
-
Save teeparham/1111804 to your computer and use it in GitHub Desktop.
Ruby ping logger
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
server = "google.com" | |
cmd = "ping -c 1 #{server}" | |
while true do | |
`#{cmd}` | |
if ($?.exitstatus != 0) | |
puts "Down: " + Time.now.to_s | |
while ($?.exitstatus != 0) do | |
`#{cmd}` | |
end | |
puts "Up: " + Time.now.to_s | |
end | |
end | |
# usage & sample output: | |
# | |
# $ ruby pingup.rb | |
# Down: 2011-07-28 09:51:24 -0600 | |
# Up: 2011-07-28 09:51:24 -0600 | |
# Down: 2011-07-28 09:51:40 -0600 | |
# Up: 2011-07-28 09:52:35 -0600 | |
# Down: 2011-07-28 09:52:49 -0600 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment