Skip to content

Instantly share code, notes, and snippets.

@teeparham
Created July 28, 2011 15:54
Show Gist options
  • Save teeparham/1111804 to your computer and use it in GitHub Desktop.
Save teeparham/1111804 to your computer and use it in GitHub Desktop.
Ruby ping logger
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