Buying a domain name is a crucial early step in building and marketing a business in the 21st century. Oftentimes it’s a Dot.Com domain. However, your first-choice search will likely be unsuccessful. Some of the reasons contributing to this include (but are not limited to) the reality that a Dot.Com is the most popular, and thanks to the ease of doing business, it’s relatively easier to start a company these days. It partially explains why more people are doing so.

most popular top-level domains worldwide as of January 2022

number of business applications in the US (2010 - 2021)

Before going down this rabbit hole, understand that you have other options than getting stuck on one domain. I went the route of tracking a domain name availability because I use to own the domain name. I had used the name for business transactions. There was a registered bank account in that name. And, also registered the name with the tax office. The cost of changing the name was pretty higher than the benefit of sticking with it.

options when dot.com domain is unavailable

If you are happy to wait patiently, hopefully, not endlessly, this might help. Honestly, I’m writing this because I’m about to get rid of the setup as I don’t need it anymore. But wanted to document it in case I need it to use or improve it some other time.

Bot setup

There are three phases to this setup:

  • the domain checker
  • a bash script that runs the domain checker
  • and a cronjob that schedules when the script runs
bot setup - three phases

Domain checker

The domain checker script is a brief Ruby code that is split into three steps.

  1. Configures the packages we need

The #Package configuration section configures what we need for the rest of the operation. We’re using Bundler within the code to manage our Ruby gems. Given that we’re only doing two things with this bot i.e. checking domain availability and sending an email notification, these two gems (Whois, Mail) are the minimum packages we need.

# Package configuration
require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'whois-parser', '~> 1.2'
  gem 'mail', '~> 2.7', '>= 2.7.1'
end
  1. Checks the availability status of a domain

At this stage, we can now specify the domain we want to track its availability status. We’ll keep a record of the response so we can use it when triggering the email notification.

# Domain checker
$domain = 'domain.com'
record = Whois.whois($domain)
parser = record.parser
  1. Sends email notification

This is where we bring everything home. Based on the response from the #Domain checker step above, we can decide to trigger a notification. I didn’t mind getting a notification once a day since I knew the domain was about to expire from the then-current owner in a few weeks.

# Mail sender
def mail_sender(status_msg)
  mail = Mail.new do
    from    '[email protected]'
    to      '[email protected]'
    subject "#{$domain.capitalize} domain check"
    body    "Your domain name (#{$domain}) is #{status_msg} for purchase."
  end
  mail.delivery_method :sendmail
  mail.deliver
end

parser.available? ? mail_sender('available') : mail_sender('not available')

Here’s what the entire domain_checker_script.rb code looks like.

# Package configuration
require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'whois-parser', '~> 1.2'
  gem 'mail', '~> 2.7', '>= 2.7.1'
end

# Domain checker
$domain = 'domain.com'
record = Whois.whois($domain)
parser = record.parser

# Mail sender
def mail_sender(status_msg)
  mail = Mail.new do
    from    '[email protected]'
    to      '[email protected]'
    subject "#{$domain.capitalize} domain check"
    body    "Your domain name (#{$domain}) is #{status_msg} for purchase."
  end
  mail.delivery_method :sendmail
  mail.deliver
end

parser.available? ? mail_sender('available') : mail_sender('not available')

Bash script that runs the domain checker

In my case, I was neither interested in setting up a server nor a Lambda function to run this for me. I was fine with using my personal computer as the server because I switch it on most days. What I have here is a one-line bash script (script.sh) that locates the directory where the domain_checker_script.rb lives and runs it.

cd ~/directory/DomainChecker && ruby domain_checker_script.rb

A cronjob that schedules when the script runs

The last step was to setup a cronjob that runs 9:30am of everyday. This triggers the bash script that runs the domain checker.

30 09 * * * ~/directory/DomainChecker/script.sh

example email

Final note

  • This approach is for when you’re happy to wait patently, hopefully not endlessly.
  • If you’re happy to pay $99/mo or $995/yr, you can use tools like DomainTools to achieve this goal without following the steps I’ve stated above.
  • If you feel like it, you can extend the above solution by letting it run on a server or a Lambda function. You can even extend it to track multple domains.
  • Like so many things in our lives, “Ona kan o w’oja” i.e. There’s no one way to the market.