Created
January 18, 2011 14:12
-
-
Save adeolaawoyemi/784477 to your computer and use it in GitHub Desktop.
ping a list of servers to know if they are available
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
# script to ping server for activity | |
# Author: Adeola Awoyemi ([email protected]) | |
require 'net/http' | |
require 'uri' | |
urls = [ | |
'http://www.photobox.co.uk/', | |
'http://www.idontexist.co.uk/' | |
] | |
sleep_secs = 10 | |
while 1 | |
puts "-" * 72 | |
urls.each do |u| | |
puts "CHECKING: #{u}:" | |
url = URI.parse("#{u}") | |
req = Net::HTTP::Get.new(url.path) | |
begin | |
res = Net::HTTP.start(url.host, url.port) {|http| | |
http.request(req) | |
} | |
# puts "\t#{res.inspect}" | |
puts "\t#{res.code} : #{res.message}" | |
rescue SocketError => se | |
puts "\tDANGER! DANGER! Will Robinson... #{se}" | |
end | |
end | |
puts "sleeping for #{sleep_secs}...\n" | |
sleep_secs.times {|i| STDOUT.write "."*i; STDOUT.flush; sleep 1 } | |
puts ""; | |
# sleep(sleep_secs) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment