require 'net/http' require 'date' # Fetches the first argument passed to the script, if no is given # it raises and error with this simple custom message. unless @domain = ARGV.first raise "You need to pass in a domain like www.6wunderkinder.com" end puts "[#{DateTime.now}] Started the DNS check for #{@domain}..." # Sends a simple GET request to the given domain and checks # if the response was 200 OK. def do_request uri = URI("http://#{@domain}") response = Net::HTTP.get_response(uri) response.is_a?(Net::HTTPOK) end # Puts a NotFound message and sleeps for 60 seconds as long as the # request is not a 200 OK. If there is a 200 OK coming back it puts # the success message and the script terminates. begin while do_request == false puts "[#{DateTime.now}] NotFound: #{@domain}..." sleep 60 end puts "[#{DateTime.now}] Success: #{@domain} is up and running!" puts "[#{DateTime.now}] Done." # If something went wrong, any error occurs the script terminates # with a error message. rescue => e puts "[#{DateTime.now}] Error: We couldn't reach #{@domain}!" puts "[#{DateTime.now}] Error: #{e.message}" puts "[#{DateTime.now}] Canceled." end